Class EDFSchedulerThreadPool

java.lang.Object
ca.spottedleaf.concurrentutil.scheduler.Scheduler
ca.spottedleaf.concurrentutil.scheduler.EDFSchedulerThreadPool

public final class EDFSchedulerThreadPool extends Scheduler
Scheduler thread pool implementation that uses EDF scheduling.

Intermediate task execution is not supported in this scheduler.

NUMA aware scheduling is not supported in this scheduler.

  • Constructor Summary

    Constructors
    Constructor
    Description
    EDFSchedulerThreadPool(int threads, ThreadFactory threadFactory)
    Creates, but does not start, a scheduler thread pool with the specified number of threads created using the specified thread factory.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns false if the task is not scheduled or is cancelled, returns true if the task was cancelled by this thread
    Returns all threads in the scheduler that are alive.
    Returns all threads in the scheduler which are allocated for executing tasks.
    Returns an array of the underlying scheduling threads.
    void
    Attempts to prevent further execution of tasks.
    boolean
    join(long msToWait)
    Waits until all threads in this pool have shutdown, or until the specified time has passed.
    boolean
    joinInterruptable(long msToWait)
    Waits until all threads in this pool have shutdown, or until the specified time has passed.
    void
    Indicates that intermediate tasks are available to be executed by the task.
    void
    Schedules the specified task to be executed on this thread pool.
    void
    Starts the threads in this pool.
    boolean
    updateTickStartToMax(ca.spottedleaf.concurrentutil.scheduler.EDFSchedulerThreadPool.ScheduledState task, long newStart)
    Updates the tasks scheduled start to the maximum of its current scheduled start and the specified new start.

    Methods inherited from class java.lang.Object

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

    • EDFSchedulerThreadPool

      public EDFSchedulerThreadPool(int threads, ThreadFactory threadFactory)
      Creates, but does not start, a scheduler thread pool with the specified number of threads created using the specified thread factory.
      Parameters:
      threads - Specified number of threads
      threadFactory - Specified thread factory
      See Also:
  • Method Details

    • start

      public void start()
      Starts the threads in this pool.
    • halt

      public void halt()
      Description copied from class: Scheduler
      Attempts to prevent further execution of tasks.
      Specified by:
      halt in class Scheduler
    • join

      public boolean join(long msToWait)
      Description copied from class: Scheduler
      Waits until all threads in this pool have shutdown, or until the specified time has passed.
      Specified by:
      join in class Scheduler
      Parameters:
      msToWait - Maximum time to wait.
      Returns:
      false if the maximum time passed, true otherwise.
    • joinInterruptable

      public boolean joinInterruptable(long msToWait) throws InterruptedException
      Description copied from class: Scheduler
      Waits until all threads in this pool have shutdown, or until the specified time has passed.
      Specified by:
      joinInterruptable in class Scheduler
      Parameters:
      msToWait - Maximum time to wait.
      Returns:
      false if the maximum time passed, true otherwise.
      Throws:
      InterruptedException - If this thread is interrupted.
    • getThreads

      public Thread[] getThreads()
      Returns an array of the underlying scheduling threads.
    • getCoreThreads

      public Thread[] getCoreThreads()
      Description copied from class: Scheduler
      Returns all threads in the scheduler which are allocated for executing tasks.
      Specified by:
      getCoreThreads in class Scheduler
    • getAliveThreads

      public Thread[] getAliveThreads()
      Description copied from class: Scheduler
      Returns all threads in the scheduler that are alive.
      Specified by:
      getAliveThreads in class Scheduler
    • schedule

      public void schedule(SchedulableTick task)
      Description copied from class: Scheduler
      Schedules the specified task to be executed on this thread pool.
      Specified by:
      schedule in class Scheduler
      Parameters:
      task - Specified task
      See Also:
    • updateTickStartToMax

      public boolean updateTickStartToMax(ca.spottedleaf.concurrentutil.scheduler.EDFSchedulerThreadPool.ScheduledState task, long newStart)
      Updates the tasks scheduled start to the maximum of its current scheduled start and the specified new start. If the task is not scheduled, returns false. Otherwise, returns whether the scheduled start was updated. Undefined behavior of the specified task is scheduled in another executor.
      Parameters:
      task - Specified task
      newStart - Specified new start
    • cancel

      public boolean cancel(SchedulableTick task)
      Description copied from class: Scheduler
      Returns false if the task is not scheduled or is cancelled, returns true if the task was cancelled by this thread
      Specified by:
      cancel in class Scheduler
    • notifyTasks

      public void notifyTasks(SchedulableTick task)
      Description copied from class: Scheduler
      Indicates that intermediate tasks are available to be executed by the task.
      Specified by:
      notifyTasks in class Scheduler
      Parameters:
      task - The specified task
      See Also: