|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjut.util.concurrent.BlockingThreadPool
public class BlockingThreadPool
executor running tasks in a thread pool. other than any ThreadPoolExecutor, this
executor's execute(Runnable) method blocks if the all threads are busy and the task
queue is full. additionally, this executor can be configured to run tasks in the current thread
instead of in a thread pool.
this class solves the problem that in the standard JDK there is no blocking Executor.
this class is especially suited if thousands or millions of small tasks are created which could
lead - with the standard ThreadPoolExecutor - either to high memory requirements or to
RejectedExecutionExceptions.
| Constructor Summary | |
|---|---|
BlockingThreadPool(int poolSize,
int queueSize)
create a blocking executor running tasks either in a thread pool or in the current thread. |
|
| Method Summary | |
|---|---|
void |
execute(Runnable command)
execute the given command at some time in the future. the command is either executed in a pooled thread or in the calling thread, depending on the BlockingThreadPool
configuration. |
void |
shutdown()
initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. this method returns immediately. it does not wait for the task execution to finish. invocation has no additional effect if already shut down. |
void |
shutdownWait()
initiates an orderly shutdown (see shutdown() and waits for the task execution to
finish. to avoid deadlocks, this method must not be called from one of the thread pool's
threads. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public BlockingThreadPool(int poolSize,
int queueSize)
poolSize - - the number of threads to keep in the pool. if set to 0 or below, tasks are
run in the current thread.queueSize - - the number of tasks to accept in queue before blocking when calling
execute(Runnable), i.e., initially a BlockingThreadPool will accept
[poolSize] + [queueSize] tasks, blocking when more are added until other tasks are
finished. if set to 0 or below, a 1-element queue is used.| Method Detail |
|---|
public void execute(Runnable command)
BlockingThreadPool
configuration.
execute in interface Executorcommand - - the task to executepublic void shutdown()
public void shutdownWait()
shutdown() and waits for the task execution to
finish. to avoid deadlocks, this method must not be called from one of the thread pool's
threads.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||