-
- All Known Implementing Classes:
ThreadPool
public interface WorkerPool
TheWorkerPool
interface models an abstract pool of workers (threads) which can executeWorkerTask
s concurrently.- Version:
- 1.9
- Author:
- Frank Fock
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
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 Detail
-
execute
void execute(WorkerTask task)
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
boolean tryToExecute(WorkerTask task)
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.
-
-