Class SchedulerQueue

java.lang.Object
org.simpleframework.common.thread.SchedulerQueue

class SchedulerQueue extends Object
The SchedulerQueue object is used to schedule tasks for execution. This queues the task for the requested period of time before it is executed. It ensures that the delay is adhered to such that tasks can be timed for execution in an accurate way.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    This is the actual scheduler used to schedule the tasks.
    private final ThreadFactory
    This is the factory used to create the worker threads.
  • Constructor Summary

    Constructors
    Constructor
    Description
    SchedulerQueue(Class type, int size)
    Constructor for the SchedulerQueue object.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    The execute method is used to queue the task for execution.
    void
    execute(Runnable task, long delay)
    This will execute the task within the executor after the time specified has expired.
    void
    execute(Runnable task, long delay, TimeUnit unit)
    This will execute the task within the executor after the time specified has expired.
    void
    This is used to stop the executor by interrupting all running tasks and shutting down the threads within the pool.
    void
    stop(long wait)
    This is used to stop the executor by interrupting all running tasks and shutting down the threads within the pool.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • executor

      private final ScheduledThreadPoolExecutor executor
      This is the actual scheduler used to schedule the tasks.
    • factory

      private final ThreadFactory factory
      This is the factory used to create the worker threads.
  • Constructor Details

    • SchedulerQueue

      public SchedulerQueue(Class type, int size)
      Constructor for the SchedulerQueue object. This will create a scheduler with a fixed number of threads to use before execution. Depending on the types of task that are to be executed this should be increased for accuracy.
      Parameters:
      type - this is the type of task to execute
      size - this is the number of threads for the scheduler
  • Method Details

    • execute

      public void execute(Runnable task)
      The execute method is used to queue the task for execution. If all threads are busy the provided task is queued and waits until all current and outstanding tasks are finished.
      Parameters:
      task - this is the task to be queued for execution
    • execute

      public void execute(Runnable task, long delay)
      This will execute the task within the executor after the time specified has expired. If the time specified is zero then it will be executed immediately. Once the scheduler has been stopped then this method will no longer accept runnable tasks.
      Parameters:
      task - this is the task to schedule for execution
      delay - the time in milliseconds to wait for execution
    • execute

      public void execute(Runnable task, long delay, TimeUnit unit)
      This will execute the task within the executor after the time specified has expired. If the time specified is zero then it will be executed immediately. Once the scheduler has been stopped then this method will no longer accept runnable tasks.
      Parameters:
      task - this is the task to schedule for execution
      delay - this is the delay to wait before execution
      unit - this is the duration time unit to wait for
    • stop

      public void stop()
      This is used to stop the executor by interrupting all running tasks and shutting down the threads within the pool. This will return once it has been stopped, and no further tasks will be accepted by this pool for execution.
    • stop

      public void stop(long wait)
      This is used to stop the executor by interrupting all running tasks and shutting down the threads within the pool. This will return once it has been stopped, and no further tasks will be accepted by this pool for execution.
      Parameters:
      wait - the number of milliseconds to wait for it to stop