org.sblim.cimclient.internal.util

Class ThreadPool

public class ThreadPool extends Object

Class ThreadPool implements a pool that manages threads and executes submitted tasks using this threads.
Constructor Summary
ThreadPool(int pMinPoolSize, int pMaxPoolSize, int pToleratedBacklog, long pToleratedIdle, ThreadGroup pGroup, String pWorkerName)
Ctor
Method Summary
booleanexecute(Runnable task, boolean enqueue)
Submits a task for execution
protected ThreadGroupgetGroup()
Gets the associated thread group
longgetIdleTimeOutMs()
Returns the idle timeout
protected voidremoveThread(ThreadPool.Worker worker)
Removes a worker from the pool.
voidshutdown()
Shuts down the thread pool and all workers
booleantaskCompleted(ThreadPool.Worker worker, boolean timedOut)
Used by the worker to report task completion and ask for a new task

Constructor Detail

ThreadPool

public ThreadPool(int pMinPoolSize, int pMaxPoolSize, int pToleratedBacklog, long pToleratedIdle, ThreadGroup pGroup, 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(Runnable task, boolean enqueue)
Submits a task for execution

Parameters: task The task enqueue if true the task will be enqueued if no worker is free, otherwise the task is executed immediately or not at all.

Returns: true if the task was executed or enqueued, false otherwise.

getGroup

protected ThreadGroup getGroup()
Gets the associated thread group

Returns: The thread group

getIdleTimeOutMs

public long getIdleTimeOutMs()
Returns the idle timeout

Returns: The timeout

removeThread

protected void removeThread(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

taskCompleted

public boolean taskCompleted(ThreadPool.Worker worker, boolean timedOut)
Used by the worker to report task completion and ask for a new task

Parameters: worker The worker timedOut true if the worker has been idle and reached timeout

Returns: true if the worker shall stay alive, false if it shall shut down itself

Copyright © 2005, 2009 IBM Corporation. All Rights Reserved.