Package edu.jas.util

Class ThreadPool

java.lang.Object
edu.jas.util.ThreadPool

public class ThreadPool extends Object
Thread pool using stack / list workpile.
  • Field Details

    • DEFAULT_SIZE

      static final int DEFAULT_SIZE
      Default number of threads to use.
      See Also:
    • size

      final int size
      Number of threads to use.
    • workers

      protected PoolThread[] workers
      Array of workers.
    • idleworkers

      protected int idleworkers
      Number of idle workers.
    • shutdown

      protected volatile boolean shutdown
      Shutdown request.
    • jobstack

      protected LinkedList<Runnable> jobstack
      Work queue / stack.
    • strategy

      protected StrategyEnumeration strategy
    • logger

      private static final org.apache.logging.log4j.Logger logger
    • debug

      private static final boolean debug
  • Constructor Details

    • ThreadPool

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

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

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

      public ThreadPool(StrategyEnumeration strategy, int size)
      Constructs a new ThreadPool.
      Parameters:
      strategy - for job processing.
      size - of the pool.
  • Method Details

    • init

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

      public String toString()
      toString.
      Overrides:
      toString in class Object
    • getNumber

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

      public StrategyEnumeration getStrategy()
      get used strategy.
    • terminate

      public void terminate()
      Terminates the threads.
    • cancel

      public int cancel()
      Cancels the threads.
    • addJob

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

      protected Runnable getJob() throws InterruptedException
      get a job for processing.
      Throws:
      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.