Class ThreadPool
java.lang.Object
org.sblim.wbem.util.ThreadPool
Class ThreadPool implements a pool that manages threads and executes
submitted tasks using this threads.
-
Constructor Summary
ConstructorsConstructorDescriptionThreadPool(int pMinPoolSize, int pMaxPoolSize, ThreadGroup pGroup, String pWorkerName) Ctor -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanSubmits a task for executionprotected ThreadGroupgetGroup()Gets the associated thread grouplongReturns the idle timeoutprotected voidremoveThread(org.sblim.wbem.util.ThreadPool.Worker worker) Removes a worker from the pool.voidshutdown()Shuts down the thread pool and all workersbooleantaskCompleted(org.sblim.wbem.util.ThreadPool.Worker worker, boolean timedOut) Used by the worker to report task completion and ask for a new task
-
Constructor Details
-
ThreadPool
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.pGroup- Then thread group to put the worker threads inpWorkerName- The name to use for worker threads
-
-
Method Details
-
getIdleTimeOutMs
public long getIdleTimeOutMs()Returns the idle timeout- Returns:
- The timeout
-
execute
-
execute
Submits a task for execution- Parameters:
task- The taskenqueue- iftruethe task will be enqueued if no worker is free, otherwise the task is executed immediately or not at all.- Returns:
trueif the task was executed or enqueued,falseotherwise.
-
getGroup
-
taskCompleted
public boolean taskCompleted(org.sblim.wbem.util.ThreadPool.Worker worker, boolean timedOut) Used by the worker to report task completion and ask for a new task- Parameters:
worker- The workertimedOut-trueif the worker has been idle and reached timeout- Returns:
trueif the worker shall stay alive,falseif it shall shut down itself
-
removeThread
protected void removeThread(org.sblim.wbem.util.ThreadPool.Worker worker) Removes a worker from the pool.- Parameters:
worker- The worker
-
shutdown
public void shutdown()Shuts down the thread pool and all workers
-