Java Reference

Scheduler

Overview

API Components

This section describes the Scheduler component.

Scheduler

The Scheduler has the following interface:

API: Scheduler component
public interface Scheduler {

    //--- General operation ---

    // Terminates the scheduler:
    void shutdown() throws Exception;

    //--- Execute a runnable in another thread ---

    // Immediately executes a {@code Runnable} in the worker thread pool:
    void execute(Runnable runnable);

    // Executes the Runnable in a newly-created thread:
    Thread startThread(String name, boolean daemon, Runnable runnable);

    //--- Scheduled callbacks ---

    // Schedules a Runnable that is executed "delay" number of msec in the future:
    ScheduledFuture<?> scheduleCallback(Runnable command, long delay);

    // Schedules a Runnable that is executed in the future after some number of random msec:
    ScheduledFuture<?> scheduleCallback(Runnable command, long delay, double min, double max);

    // Schedules a Runnable that is executed at the specified Date:
    ScheduledFuture<?> scheduleCallback(Runnable command, Date date);

    //--- Recurring callbacks ---

    // Schedules a Runnable that is executed on a recurring basis (option 1):
    ScheduledFuture<?> scheduleCallbackAtFixedRate(Runnable command, long initialDelay, long period);

    // Schedules a Runnable that is executed on a recurring basis (option 2):
    ScheduledFuture<?> scheduleCallbackAtFixedRate(Runnable command, Date date, long period);

    // Schedules a Runnable that is executed on a recurring basis (option 3):
    ScheduledFuture<?> scheduleCallbackWithFixedDelay(Runnable command, long initialDelay, long delay);

    //--- Convenience ---

    // Wrapper for Thread.sleep() with default exception handling:
    void sleep(long msec);

    //--- Executor services and thread factory ---

    // Returns the *primary* worker thread pool executor:
    ExecutorService getWorkerThreadPool();

    // Returns the *scheduled* thread pool executor:
    ScheduledThreadPoolExecutor getScheduledThreadPool();

    // Returns a ThreadFactory that names new threads based on the provided "name":
    ThreadFactory getNamedThreadFactory(String name);
}

Example Code

This section gives some sample code using the KOS Scheduler object.

Source code for this and most other Java reference pages is available on GitHub.

Summary

Previous
Next
On this page
Java Development
Seamlessly transition from Legacy+ systems to Freestyle microdosing and advanced distributed dispense systems.
UI Development
Using KOS SDKs, integrating Consumer and Non-consumer facing UIs becomes seamless, giving you less hassle and more time to create.
Video Library
Meet some of our development team, as they lead you through the tools, features, and tips and tricks of various KOS tools.
Resources
Familiarize yourself with KOS terminology, our reference materials, and explore additional resources that complement your KOS journey.
Copyright © 2024 TCCC. All rights reserved.