Package com.nt.udc.util.threadpool
Class ThreadPool
java.lang.Object
com.nt.udc.util.threadpool.ThreadPool
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
createId()
create's an ID for the worker threadsvoid
performTask
(PoolTask task) ask the pool to perform a task.void
shutdown()
Stop all threads.boolean
taskCompleted
(com.nt.udc.util.threadpool.Worker w) worker threads should call this methods after it has completed its task.
-
Constructor Details
-
ThreadPool
- Parameters:
size
- number of threads in this poollogger
- log messages to this
-
-
Method Details
-
performTask
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
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
-