Class ScheduledObjectOneWorkRunnable<O>

Type Parameters:
O - The type of object for which to run.
All Implemented Interfaces:
ManagedRunnable, ObjectRunnable<O,O>, Runnable

A runnable that will enqueue a delayed object runnable as soon as the delay elapsed.
This runnable is used within a scheduled executor. When running, it removes the delayed runnable from the corresponding runtime data and makes it available as new (pending) work to be executed normally. Whether the work is then before or after a flush depends on whether a flush is currently pending or whether the executor should block until after flush if there has already been work done for this object after the previous flush.
The delayed runnable is enqueued even while a flush is pending: enqueueing routes through the executor which defers the work to after the flush (or refuses and cancels it), so no work is executed while a flush is pending and delayed work whose delay elapses within a flush is not lost. Only the delayed work this runnable has been created for is enqueued: the delayed work of the object may have been replaced meanwhile, and the replacement is enqueued by its own runnable when its own delay elapses. This runnable executes no work itself, so the termination counter does not matter to it.
  • Field Details

    • delayed

      protected final Runnable delayed
      The delayed work which this runnable enqueues when the delay has elapsed, or null for a runnable which enqueues whatever delayed work its object has.
  • Constructor Details

    • ScheduledObjectOneWorkRunnable

      @Deprecated(since="18.0.0", forRemoval=true) public ScheduledObjectOneWorkRunnable(O object, ScheduledObjectOneWorkExecutor<O> executor, AtomicInteger terminate, Logger logger)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use ScheduledObjectOneWorkRunnable(Object, Runnable, ScheduledObjectOneWorkExecutor, AtomicInteger, Logger) instead. A runnable created without its delayed work enqueues whatever delayed work its object has when the delay elapses, so it may enqueue a replacement long before the delay of the replacement has elapsed.
      Creates a new ObjectRunnable that enqueues a delayed runnable to be executed for a specific object after a specific delay.
      Parameters:
      object - The object of this runnable.
      executor - The executor to which to add the delayed runnable.
      terminate - The amount of termination requests. This allows for synchronising across different objects.
      logger - The logger which to use for the progress of enqueueing the delayed runnable.
    • ScheduledObjectOneWorkRunnable

      public ScheduledObjectOneWorkRunnable(O object, Runnable delayed, ScheduledObjectOneWorkExecutor<O> executor, AtomicInteger terminate, Logger logger)
      Creates a new ObjectRunnable that enqueues a delayed runnable to be executed for a specific object after a specific delay.
      Parameters:
      object - The object of this runnable.
      delayed - The delayed work which this runnable enqueues when the delay has elapsed. Only exactly this work is enqueued: the delayed work of the object may have been replaced meanwhile, and the replacement is enqueued by its own runnable.
      executor - The executor to which to add the delayed runnable.
      terminate - The amount of termination requests. This allows for synchronising across different objects.
      logger - The logger which to use for the progress of enqueueing the delayed runnable.
  • Method Details

    • runForObject

      protected boolean runForObject()
      Description copied from class: AbstractObjectRunnable
      Runs this runnable actually. Counting the executions and signalling the termination are already handled, implementations only need to react to termination requests.

      An execution which has been submitted but has not started yet is awaited by a flush as well: it executes the work of its object as soon as it starts, so work which has been submitted before the flush completes before the task of the flush and no work runs concurrently to this task.

      Specified by:
      runForObject in class AbstractObjectRunnable<O,O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData,ScheduledObjectOneWorkExecutor<O>>
      Returns:
      Whether the work for the object has been terminated. Otherwise there is work left and another execution of this runnable continues it. With a termination request, return true, only return false if you want to continue to work without interruption, e. g. to change the executing thread. The return value is informational, the termination is signalled based on the submitted and running executions.