Class ThreadPool


  • public class ThreadPool
    extends java.lang.Object
    Class ThreadPool implements a pool that manages threads and executes submitted tasks using this threads.
    • Constructor Summary

      Constructors 
      Constructor Description
      ThreadPool​(int pMinPoolSize, int pMaxPoolSize, int pToleratedBacklog, long pToleratedIdle, java.lang.ThreadGroup pGroup, java.lang.String pWorkerName)
      Ctor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean execute​(java.lang.Runnable task)
      Submits a task for execution
      protected java.lang.ThreadGroup getGroup()
      Gets the associated thread group
      java.lang.Runnable getNextTask​(org.sblim.cimclient.internal.util.ThreadPool.Worker worker)
      Get a new task.
      protected void removeWorker​(org.sblim.cimclient.internal.util.ThreadPool.Worker worker)
      Removes a worker from the pool.
      void shutdown()
      Shuts down the thread pool and all workers
      void taskCompleted()
      Notifies the pool that at task was completed.
      void taskStarted()
      Notifies the pool that at task was started.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ThreadPool

        public ThreadPool​(int pMinPoolSize,
                          int pMaxPoolSize,
                          int pToleratedBacklog,
                          long pToleratedIdle,
                          java.lang.ThreadGroup pGroup,
                          java.lang.String pWorkerName)
        Ctor
        Parameters:
        pMinPoolSize - The minimal pool size. The pool will always keep at least this number of worker threads alive even in no load situations.
        pMaxPoolSize - The maximal pool size. The pool will create up to that number of worker threads on heavy load.
        pToleratedBacklog - The task backlog that is tolerated before an additional worker is created
        pToleratedIdle - The idle time of a worker that is tolerated before the worker is destroyed
        pGroup - Then thread group to put the worker threads in
        pWorkerName - The name to use for worker threads
    • Method Detail

      • execute

        public boolean execute​(java.lang.Runnable task)
        Submits a task for execution
        Parameters:
        task - The task
        Returns:
        true if the task was executed or enqueued, false otherwise.
      • removeWorker

        protected void removeWorker​(org.sblim.cimclient.internal.util.ThreadPool.Worker worker)
        Removes a worker from the pool.
        Parameters:
        worker - The worker
      • getGroup

        protected java.lang.ThreadGroup getGroup()
        Gets the associated thread group
        Returns:
        The thread group
      • getNextTask

        public java.lang.Runnable getNextTask​(org.sblim.cimclient.internal.util.ThreadPool.Worker worker)
                                       throws java.lang.InterruptedException
        Get a new task. If no task was available during the timeout period the calling worker might be killed if more than the minimum number of workers exist
        Parameters:
        worker - The worker asking for a new task
        Returns:
        The next available task from the queue. If no task is available waits for idle timeout and returns null afterwards.
        Throws:
        java.lang.InterruptedException - on interrupt
      • taskStarted

        public void taskStarted()
        Notifies the pool that at task was started. Effectively decrements the idle worker count.
      • taskCompleted

        public void taskCompleted()
        Notifies the pool that at task was completed. Effectively increments the idle worker count.
      • shutdown

        public void shutdown()
        Shuts down the thread pool and all workers