Class TaskScheduler

java.lang.Object
org.snmp4j.util.TaskScheduler
All Implemented Interfaces:
Runnable

public class TaskScheduler extends Object implements Runnable
The TaskScheduler uses a ThreadPool to recurrent execute SchedulerTasks.
Since:
1.6
Version:
1.6
Author:
Frank Fock
  • Field Details

    • schedulerTimeout

      protected long schedulerTimeout
  • Constructor Details

    • TaskScheduler

      public TaskScheduler(ThreadPool threadPool)
      Creates a TaskScheduler that uses the supplied ThreadPool to execute tasks.
      Parameters:
      threadPool - a ThreadPool.
  • Method Details

    • addTask

      public void addTask(SchedulerTask task)
      Adds a task to the scheduler.
      Parameters:
      task - a SchedulerTask.
    • removeTask

      public boolean removeTask(SchedulerTask task)
      Removes a task from the scheduler.
      Parameters:
      task - the SchedulerTask to be removed from the scheduler
      Returns:
      true if 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 TaskScheduler monitor is held only while the task list is being inspected/mutated. Submission to the ThreadPool (including the wait for capacity when the pool is busy) happens without the TaskScheduler.this monitor, so concurrent addTask(SchedulerTask), removeTask(SchedulerTask), and clear() calls — including recursive addTask invocations from worker threads running in the pool itself — cannot deadlock against a saturated pool.

      Specified by:
      run in interface Runnable
    • setStop

      public void setStop(boolean stop)
      Stops the schedulers run method.
      Parameters:
      stop - true to stop the scheduler.
    • isStop

      public boolean isStop()
      Checks if the scheduler is (to be) stopped.
      Returns:
      true if the scheduler has been stopped or is being stopped.