|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.rhi.architecture.threads.ThreadPoolImpl
Custom ThreadPool Implementation. The ThreadPool is started with predefined set of WorkerThreads which actually perform the work. This ThreadPool is suitable for scenarios work is split across mutiple threads and main thread waits for all the worker threads to finish and assigns work to all (or part) of worker threads. The ThreadPool can be asked to find a worked thread and assign work to it using execute method. Using join() method the caller will wait for all the worker threads to finish. IMPORTANT NOTE(S): 1. This ThreadPool is suitable for use by a single thread, not by mutliple threads/requests requesting ThreadPool to execute work. 2. It is the responsibility of the caller to make sure that it requests at maximum 'poolsize' amount of work to be performed by the ThreadPool. If no workers are free an RuntimeException is thrown.
Constructor Summary | |
ThreadPoolImpl(int size)
Constructor - constructs a ThreadPool of given size. |
Method Summary | |
void |
close()
Mark all threads to shutdown and notify them, just in case they are sleeping. |
void |
execute(java.lang.Runnable work)
Executes a given 'work'. |
void |
join()
Wait for all the worker threads to finish. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ThreadPoolImpl(int size)
size
- - size of the poolMethod Detail |
public void execute(java.lang.Runnable work) throws java.lang.RuntimeException
execute
in interface ThreadPool
work
- - work to be performed.
java.lang.RuntimeException
public void join()
join
in interface ThreadPool
public void close()
close
in interface ThreadPool
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |