Package edu.jas.util

Class DistThreadPool


  • public class DistThreadPool
    extends java.lang.Object
    Distributed thread pool. Using stack / list work-pile and Executable Channels and Servers.
    Author:
    Heinz Kredel
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int idleworkers
      Number of idle workers.
      protected java.util.LinkedList<java.lang.Runnable> jobstack
      Work queue / stack.
      protected StrategyEnumeration strategy  
      protected int threads
      Number of threads to use.
      protected edu.jas.util.DistPoolThread[] workers
      Array of workers.
    • Constructor Summary

      Constructors 
      Constructor Description
      DistThreadPool()
      Constructs a new DistThreadPool with strategy StrategyEnumeration.FIFO and size DEFAULT_SIZE.
      DistThreadPool​(int size)
      Constructs a new DistThreadPool with strategy StrategyEnumeration.FIFO.
      DistThreadPool​(int size, java.lang.String mfile)
      Constructs a new DistThreadPool with strategy StrategyEnumeration.FIFO.
      DistThreadPool​(StrategyEnumeration strategy)
      Constructs a new DistThreadPool with size DEFAULT_SIZE.
      DistThreadPool​(StrategyEnumeration strategy, int size, java.lang.String mfile)
      Constructs a new DistThreadPool.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addJob​(java.lang.Runnable job)
      adds a job to the workpile.
      ExecutableChannels getEC()
      the used executable channel.
      protected java.lang.Runnable getJob()
      get a job for processing.
      int getNumber()
      number of worker threads.
      StrategyEnumeration getStrategy()
      get used strategy.
      boolean hasJobs()
      check if there are jobs for processing.
      boolean hasJobs​(int n)
      check if there are more than n jobs for processing.
      void init()
      thread initialization and start.
      void terminate()
      Terminates the threads.
      void terminate​(boolean shutDown)
      Terminates the threads.
      java.lang.String toString()
      String representation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • threads

        protected final int threads
        Number of threads to use.
      • workers

        protected edu.jas.util.DistPoolThread[] workers
        Array of workers.
      • idleworkers

        protected int idleworkers
        Number of idle workers.
      • jobstack

        protected java.util.LinkedList<java.lang.Runnable> jobstack
        Work queue / stack.
    • Constructor Detail

      • DistThreadPool

        public DistThreadPool()
        Constructs a new DistThreadPool with strategy StrategyEnumeration.FIFO and size DEFAULT_SIZE.
      • DistThreadPool

        public DistThreadPool​(StrategyEnumeration strategy)
        Constructs a new DistThreadPool with size DEFAULT_SIZE.
        Parameters:
        strategy - for job processing.
      • DistThreadPool

        public DistThreadPool​(int size)
        Constructs a new DistThreadPool with strategy StrategyEnumeration.FIFO.
        Parameters:
        size - of the pool.
      • DistThreadPool

        public DistThreadPool​(int size,
                              java.lang.String mfile)
        Constructs a new DistThreadPool with strategy StrategyEnumeration.FIFO.
        Parameters:
        size - of the pool.
        mfile - machine file.
      • DistThreadPool

        public DistThreadPool​(StrategyEnumeration strategy,
                              int size,
                              java.lang.String mfile)
        Constructs a new DistThreadPool.
        Parameters:
        strategy - for job processing.
        size - of the pool.
        mfile - machine file.
    • Method Detail

      • toString

        public java.lang.String toString()
        String representation.
        Overrides:
        toString in class java.lang.Object
      • init

        public void init()
        thread initialization and start.
      • getNumber

        public int getNumber()
        number of worker threads.
      • terminate

        public void terminate​(boolean shutDown)
        Terminates the threads.
        Parameters:
        shutDown - true, if shut-down of the remote executable servers is requested, false, if remote executable servers stay alive.
      • terminate

        public void terminate()
        Terminates the threads.
      • addJob

        public void addJob​(java.lang.Runnable job)
        adds a job to the workpile.
        Parameters:
        job -
      • getJob

        protected java.lang.Runnable getJob()
                                     throws java.lang.InterruptedException
        get a job for processing.
        Throws:
        java.lang.InterruptedException
      • hasJobs

        public boolean hasJobs()
        check if there are jobs for processing.
      • hasJobs

        public boolean hasJobs​(int n)
        check if there are more than n jobs for processing.
        Parameters:
        n - Integer
        Returns:
        true, if there are possibly more than n jobs.