Top Description Fields Constructors Methods
org.springframework.scheduling.concurrent

pack-priv Class ReschedulingRunnable

extends DelegatingErrorHandlingRunnable
implements ScheduledFuture<Object>
Class Inheritance
All Implemented Interfaces
java.util.concurrent.ScheduledFuture, java.util.concurrent.Future, java.util.concurrent.Delayed, java.lang.Comparable
Imports
java.time.Clock, .Duration, .Instant, java.util.concurrent.Delayed, .ExecutionException, .ScheduledExecutorService, .ScheduledFuture, .TimeUnit, .TimeoutException, org.springframework.lang.Nullable, org.springframework.scheduling.Trigger, org.springframework.scheduling.support.DelegatingErrorHandlingRunnable, .SimpleTriggerContext, org.springframework.util.Assert, .ErrorHandler

Internal adapter that reschedules an underlying Runnable according to the next execution time suggested by a given Trigger.

Necessary because a native ScheduledExecutorService supports delay-driven execution only. The flexibility of the Trigger interface will be translated onto a delay for the next execution time (repeatedly).

Authors
Juergen Hoeller, Mark Fisher
Since
3.0

Field Summary

Modifier and TypeField and Description
private ScheduledFuture<?>
private final ScheduledExecutorService
private Instant
private final Trigger
private final SimpleTriggerContext
private final Object

Constructor Summary

AccessConstructor and Description
public
ReschedulingRunnable(Runnable delegate, Trigger trigger, Clock clock, ScheduledExecutorService executor, ErrorHandler errorHandler)

Method Summary

Modifier and TypeMethod and Description
public boolean
cancel(boolean
true if the thread executing this task should be interrupted (if the thread is known to the implementation); otherwise, in-progress tasks are allowed to complete
mayInterruptIfRunning
)

Implements java.util.concurrent.Future.cancel.

Attempts to cancel execution of this task.
public int
compareTo(Delayed
the object to be compared.
other
)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.
public Object
get()

Implements java.util.concurrent.Future.get.

Waits if necessary for the computation to complete, and then retrieves its result.
public Object
get(long
the maximum time to wait
timeout
,
TimeUnit
the time unit of the timeout argument
unit
)

Implements java.util.concurrent.Future.get.

Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.
public long
getDelay(TimeUnit
the time unit
unit
)

Implements java.util.concurrent.Delayed.getDelay.

Returns the remaining delay associated with this object, in the given time unit.
public boolean
isCancelled()

Implements java.util.concurrent.Future.isCancelled.

Returns true if this task was cancelled before it completed normally.
public boolean
isDone()

Implements java.util.concurrent.Future.isDone.

Returns true if this task completed.
private ScheduledFuture<?>
public void
public ScheduledFuture<?>
Inherited from org.springframework.scheduling.support.DelegatingErrorHandlingRunnable:
toString

Field Detail

currentFutureback to summary
private ScheduledFuture<?> currentFuture
Annotations
@Nullable
executorback to summary
private final ScheduledExecutorService executor
scheduledExecutionTimeback to summary
private Instant scheduledExecutionTime
Annotations
@Nullable
triggerback to summary
private final Trigger trigger
triggerContextback to summary
private final SimpleTriggerContext triggerContext
triggerContextMonitorback to summary
private final Object triggerContextMonitor

Constructor Detail

ReschedulingRunnableback to summary
public ReschedulingRunnable(Runnable delegate, Trigger trigger, Clock clock, ScheduledExecutorService executor, ErrorHandler errorHandler)

Method Detail

cancelback to summary
public boolean cancel(boolean mayInterruptIfRunning)

Implements java.util.concurrent.Future.cancel.

Doc from java.util.concurrent.Future.cancel.

Attempts to cancel execution of this task. This method has no effect if the task is already completed or cancelled, or could not be cancelled for some other reason. Otherwise, if this task has not started when cancel is called, this task should never run. If the task has already started, then the mayInterruptIfRunning parameter determines whether the thread executing this task (when known by the implementation) is interrupted in an attempt to stop the task.

The return value from this method does not necessarily indicate whether the task is now cancelled; use isCancelled.

Parameters
mayInterruptIfRunning:boolean

true if the thread executing this task should be interrupted (if the thread is known to the implementation); otherwise, in-progress tasks are allowed to complete

Returns:boolean

false if the task could not be cancelled, typically because it has already completed; true otherwise. If two or more threads cause a task to be cancelled, then at least one of them returns true. Implementations may provide stronger guarantees.

Annotations
@Override
compareToback to summary
public int compareTo(Delayed other)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Parameters
other:Delayed

the object to be compared.

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Annotations
@Override
getback to summary
public Object get() throws InterruptedException, ExecutionException

Implements java.util.concurrent.Future.get.

Doc from java.util.concurrent.Future.get.

Waits if necessary for the computation to complete, and then retrieves its result.

Returns:Object

the computed result

Annotations
@Override
Exceptions
InterruptedException:
if the current thread was interrupted while waiting
ExecutionException:
if the computation threw an exception
getback to summary
public Object get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException

Implements java.util.concurrent.Future.get.

Doc from java.util.concurrent.Future.get.

Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.

Parameters
timeout:long

the maximum time to wait

unit:TimeUnit

the time unit of the timeout argument

Returns:Object

the computed result

Annotations
@Override
Exceptions
InterruptedException:
if the current thread was interrupted while waiting
ExecutionException:
if the computation threw an exception
TimeoutException:
if the wait timed out
getDelayback to summary
public long getDelay(TimeUnit unit)

Implements java.util.concurrent.Delayed.getDelay.

Doc from java.util.concurrent.Delayed.getDelay.

Returns the remaining delay associated with this object, in the given time unit.

Parameters
unit:TimeUnit

the time unit

Returns:long

the remaining delay; zero or negative values indicate that the delay has already elapsed

Annotations
@Override
isCancelledback to summary
public boolean isCancelled()

Implements java.util.concurrent.Future.isCancelled.

Doc from java.util.concurrent.Future.isCancelled.

Returns true if this task was cancelled before it completed normally.

Returns:boolean

true if this task was cancelled before it completed

Annotations
@Override
isDoneback to summary
public boolean isDone()

Implements java.util.concurrent.Future.isDone.

Doc from java.util.concurrent.Future.isDone.

Returns true if this task completed. Completion may be due to normal termination, an exception, or cancellation -- in all of these cases, this method will return true.

Returns:boolean

true if this task completed

Annotations
@Override
obtainCurrentFutureback to summary
private ScheduledFuture<?> obtainCurrentFuture()
runback to summary
public void run()

Overrides org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run.

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
scheduleback to summary
public ScheduledFuture<?> schedule()
Annotations
@Nullable