Class Cron

java.lang.Object
atessera.sensei.Cron
All Implemented Interfaces:
AutoCloseable

public class Cron extends Object implements AutoCloseable
Runs work() periodically on a dedicated daemon thread.

After each work() invocation the worker sleeps for the configured number of minutes. close() requests termination without interrupting an ongoing work() call; if the worker is currently sleeping, it is woken up so that shutdown does not wait for the whole interval.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Cron(int intervalMinutes)
    Creates and starts a cron worker.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Requests the worker thread to stop.
    protected void
    Periodic job executed by the worker thread.

    Methods inherited from class java.lang.Object

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

    • Cron

      public Cron(int intervalMinutes)
      Creates and starts a cron worker.
      Parameters:
      intervalMinutes - sleep interval in minutes; must be positive
  • Method Details

    • work

      protected void work()
      Periodic job executed by the worker thread.

      Subclasses override this method. The default implementation does nothing.

    • close

      public void close()
      Requests the worker thread to stop.

      The method never interrupts an ongoing work() call. If the worker is sleeping, it is woken up and finishes as soon as possible.

      Specified by:
      close in interface AutoCloseable