Class SimplePeriodicRunnerFactory


  • public class SimplePeriodicRunnerFactory
    extends Object
    Instances of this class will run a single Runnable task repeatedly at a rate specified in terms of an interval.

    Limitations:

    • Constructor Detail

      • SimplePeriodicRunnerFactory

        public SimplePeriodicRunnerFactory()
        Create an instance that will produce SimplePeriodicRunner instances that all share the same scheduling thread. (To avoid delays caused by long-running tasks, isolate them by using more than one instance of this factory class, so separate scheduling threads are used to run the tasks.)
    • Method Detail

      • getRunnerForInterval

        public SimplePeriodicRunner getRunnerForInterval​(Duration executionInterval)
        Get an instance of a SimplePeriodicRunner that will allow a Runnable to be executed at the rate specified via the executionInterval.
        Parameters:
        executionInterval - The desired amount of time to delay execution of the provided Runnable task after the previous start of execution of that task.
        Returns:
        The instance that will run a task at the specified interval.
      • shutdownGracefully

        public void shutdownGracefully​(long timeout,
                                       TimeUnit unit)
                                throws InterruptedException
        Wait up to a specified amount of time for a currently-running Runnable task to finish, if any, and then shut down. No more scheduled tasks will be run.
        Parameters:
        timeout - How long to wait for currently-running tasks to finish.
        unit - The units of the timeout parameter.
        Throws:
        InterruptedException - If the calling thread was interrupted while waiting for a currently-running task to finish.
      • shutdownNow

        public void shutdownNow()
        Interrupt a running task (if any) and do not run any scheduled tasks from now on.