Class ThreadPool

java.lang.Object
com.nt.udc.util.threadpool.ThreadPool

public class ThreadPool extends Object
Thread pool class used to manage a set of threads. Use this class to reduce the time for thread creation. The tasks used for assigned to the pool should have a short time span.
  • Constructor Details

    • ThreadPool

      public ThreadPool(int size, LoggerIfc logger)
      Parameters:
      size - number of threads in this pool
      logger - log messages to this
  • Method Details

    • performTask

      public void performTask(PoolTask task) throws ThreadPoolException
      ask the pool to perform a task. If there are no idle threads, it will create a worker thread for the task
      Parameters:
      task -
      Throws:
      ThreadPoolException - if the thread pool has shutdown
    • shutdown

      public void shutdown()
      Stop all threads. first all idle threads will stop. All active threads will be asked to shutdown. It will not actively end any threads. As a result any task should periodically check to see if it suppose to shutdown any call to perform task will throw an exception after this call.
    • createId

      public static String createId()
      create's an ID for the worker threads
      Returns:
      id
    • taskCompleted

      public boolean taskCompleted(com.nt.udc.util.threadpool.Worker w)
      worker threads should call this methods after it has completed its task. this method indicates if the thread should be keep alive or if it should be put to rest.
      Returns:
      true if the thread should stay alive, o.w. false