Class TaskScheduler
java.lang.Object
org.snmp4j.util.TaskScheduler
- All Implemented Interfaces:
Runnable
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTaskScheduler(ThreadPool threadPool) Creates aTaskSchedulerthat uses the suppliedThreadPoolto execute tasks. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTask(SchedulerTask task) Adds a task to the scheduler.voidclear()Removes all tasks.booleanisStop()Checks if the scheduler is (to be) stopped.booleanremoveTask(SchedulerTask task) Removes a task from the scheduler.voidrun()Runs the scheduler.voidsetStop(boolean stop) Stops the schedulers run method.
-
Field Details
-
schedulerTimeout
protected long schedulerTimeout
-
-
Constructor Details
-
TaskScheduler
Creates aTaskSchedulerthat uses the suppliedThreadPoolto execute tasks.- Parameters:
threadPool- aThreadPool.
-
-
Method Details
-
addTask
Adds a task to the scheduler.- Parameters:
task- aSchedulerTask.
-
removeTask
Removes a task from the scheduler.- Parameters:
task- theSchedulerTaskto be removed from the scheduler- Returns:
trueif the task could be removed.
-
clear
public void clear()Removes all tasks. -
run
public void run()Runs the scheduler. While in this method tasks are scheduled on the internal thread pool. The scheduler tries to schedule tasks fairly.The
TaskSchedulermonitor is held only while the task list is being inspected/mutated. Submission to theThreadPool(including thewaitfor capacity when the pool is busy) happens without theTaskScheduler.thismonitor, so concurrentaddTask(SchedulerTask),removeTask(SchedulerTask), andclear()calls — including recursiveaddTaskinvocations from worker threads running in the pool itself — cannot deadlock against a saturated pool. -
setStop
public void setStop(boolean stop) Stops the schedulers run method.- Parameters:
stop-trueto stop the scheduler.
-
isStop
public boolean isStop()Checks if the scheduler is (to be) stopped.- Returns:
trueif the scheduler has been stopped or is being stopped.
-