Package kilim

Class Scheduler

java.lang.Object
kilim.Scheduler
Direct Known Subclasses:
AffineScheduler, ForkJoinScheduler

public abstract class Scheduler extends Object
This is a basic FIFO Executor. It maintains a list of runnable tasks and hands them out to WorkerThreads. Note that we don't maintain a list of all tasks, but we will at some point when we introduce monitoring/watchdog services. Paused tasks are not GC'd because their PauseReasons ought to be registered with some other live object.
  • Field Details

    • defaultScheduler

      public static volatile Scheduler defaultScheduler
    • pinnableScheduler

      public static volatile Scheduler pinnableScheduler
    • defaultNumberThreads

      public static int defaultNumberThreads
    • taskMgr_

      private static final ThreadLocal<Task> taskMgr_
    • defaultLogger

      public static Scheduler.Logger defaultLogger
    • shutdown

      protected AtomicBoolean shutdown
    • logger

      private Scheduler.Logger logger
  • Constructor Details

    • Scheduler

      public Scheduler()
  • Method Details

    • getCurrentTask

      protected static Task getCurrentTask()
    • setCurrentTask

      protected static void setCurrentTask(Task t)
    • make

      public static Scheduler make(int numThreads)
      return a new default Scheduler with default queue length
      Parameters:
      numThreads - the number of threads to use, or use the default if less than one
      Returns:
      the new Scheduler
    • isEmptyish

      public abstract boolean isEmptyish()
      are the queues empty allows false positives, but not false negatives ie, if this method returns false, then at some moment during the call at least one queue was non-empty if it returns true then for each queue there was a moment during the call when it was empty
    • numThreads

      public abstract int numThreads()
    • isPinnable

      public boolean isPinnable()
    • schedule

      public void schedule(Task t)
      Schedule a task to run. It is the task's job to ensure that it is not scheduled when it is runnable. the default index for assignment to an executor
    • schedule

      public abstract void schedule(int index, Task t)
      schedule a task to run
      Parameters:
      index - the index of the executor to use, or less than zero to use the default (round robin) assignment
      t - the task
    • scheduleTimer

      public abstract void scheduleTimer(Timer t)
    • idledown

      public abstract void idledown()
      block the thread till a moment at which all scheduled tasks have completed and then shutdown the scheduler does not prevent scheduling new tasks (from other threads) until the shutdown is complete so such a task could be partially executed
    • shutdown

      public void shutdown()
    • isShutdown

      public boolean isShutdown()
    • logRelay

      protected static void logRelay(Scheduler sched, Object src, Object obj)
      a static accessor to allow log to be protected
    • log

      protected void log(Object src, Object obj)
      write to the log
      Parameters:
      src - the source of the log object
      obj - the object to log
    • setLogger

      public void setLogger(Scheduler.Logger logger)
      set a logger
      Parameters:
      logger - the logger
    • getDefaultScheduler

      public static Scheduler getDefaultScheduler()
      get and possibly instantiate a default scheduler
    • getDefaultPinnable

      public static Scheduler getDefaultPinnable()
      get and possibly instantiate a scheduler that is pinnable
    • getPinnable

      protected Scheduler getPinnable()
    • setDefaultScheduler

      public static void setDefaultScheduler(Scheduler s)
    • setDefaultPinnable

      public static void setDefaultPinnable(Scheduler s)