- All Known Implementing Classes:
ThreadPool
public interface WorkerPool
The
WorkerPool
interface models an abstract pool of workers
(threads) which can execute WorkerTask
s concurrently.- Version:
- 1.9
- Author:
- Frank Fock
-
Method Summary
Modifier and TypeMethodDescriptionvoid
cancel()
Cancels all threads non-blocking by interrupting them.void
execute
(WorkerTask task) Executes a task on behalf of this worker pool.boolean
isIdle()
Checks if all workers of the pool are idle.void
stop()
Stops all threads in this worker pool gracefully.boolean
tryToExecute
(WorkerTask task) Tries to execute a task on behalf of this worker pool.
-
Method Details
-
execute
Executes a task on behalf of this worker pool. If all threads are currently busy, this method call blocks until a worker gets idle again which is when the call returns immediately.- Parameters:
task
- aRunnable
to execute.
-
tryToExecute
Tries to execute a task on behalf of this worker pool. If all threads are currently busy, this method returnsfalse
. Otherwise the task is executed in background.- Parameters:
task
- aRunnable
to execute.- Returns:
true
if the task is executing.
-
stop
void stop()Stops all threads in this worker pool gracefully. This method will not return until all threads have been terminated and joined successfully. -
cancel
void cancel()Cancels all threads non-blocking by interrupting them. -
isIdle
boolean isIdle()Checks if all workers of the pool are idle.- Returns:
true
if all workers are idle.
-