|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcommon.threads.WorkerThreadPool
A thread pool that handles requests (Runnable objects) and provides some extra functionality.
User's are encouraged to use the shared instance by calling
getSharedInstance()
, but they can instantiate new pools
if they so desire. Just remember to shut down the threads when
the plugin is unloaded.
This is a less featureful version of Java 5's "ThreadPoolExecutor" and "Future" classes, with the benefit that they run on 1.4.
addRequest(Runnable)
,
addRequests(Runnable[])
,
WorkRequest
Constructor Summary | |
WorkerThreadPool()
|
Method Summary | |
WorkRequest |
addRequest(java.lang.Runnable req)
Adds a request to the pool. |
WorkRequest[] |
addRequests(java.lang.Runnable[] reqs)
Makes sure that there are enough threads to execute all requests in parallel and enqueue the requests. |
void |
ensureCapacity(int size)
Ensures that at least size threads are available to
handle requests. |
static WorkerThreadPool |
getSharedInstance()
|
WorkRequest[] |
runRequests(java.lang.Runnable[] reqs)
Immediately runs the given requests. |
void |
shutdown()
Asks all running threads to shutdown. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public WorkerThreadPool()
Method Detail |
public static WorkerThreadPool getSharedInstance()
public WorkRequest addRequest(java.lang.Runnable req)
If no threads have yet been started, a new thread is created and started.
public WorkRequest[] addRequests(java.lang.Runnable[] reqs)
So if you enqueue 4 requests and there are 4 idle threads, each request will run on a separate thread. But if one thread is running a long request, it may happen that one of the new requests might finish before that running job, and another one of the new requests will run on that same thread.
public WorkRequest[] runRequests(java.lang.Runnable[] reqs)
public void ensureCapacity(int size)
size
threads are available to
handle requests.
public void shutdown()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |