Package org.snmp4j.util
Interface WorkerPool
- All Known Implementing Classes:
ThreadPool
public interface WorkerPool
The
WorkerPool interface models an abstract pool of workers
(threads) which can execute WorkerTasks concurrently.- Version:
- 1.9
- Author:
- Frank Fock
-
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()Cancels all threads non-blocking by interrupting them.voidexecute(WorkerTask task) Executes a task on behalf of this worker pool.booleanisIdle()Checks if all workers of the pool are idle.voidstop()Stops all threads in this worker pool gracefully.booleantryToExecute(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- aRunnableto 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- aRunnableto execute.- Returns:
trueif 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:
trueif all workers are idle.
-