Package org.apache.sis.internal.system
Class DelayedRunnable
java.lang.Object
org.apache.sis.internal.system.DelayedRunnable
- All Implemented Interfaces:
Comparable<Delayed>
,Runnable
,Delayed
- Direct Known Subclasses:
ConcurrentAuthorityFactory.CloseTask
,DelayedRunnable.Immediate
,MetadataSource.CloseTask
A task to be submitted to
DelayedExecutor
for later execution.
Design note:
we considered removing this interface in favor a library-wide executor instead of
DelayedExecutor
.
But benchmarks suggested that this lightweight approach for the specific needs of SIS is preferable.
See SIS-76 for more information.- Since:
- 0.3
- Version:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
A "delayed" task which is actually executed as soon as possible. -
Field Summary
FieldsModifier and TypeFieldDescription(package private) final long
Time of execution of this task, in nanoseconds provided bySystem.nanoTime()
. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
DelayedRunnable
(int delay, TimeUnit unit) Creates a new task to be executed after the given delay.protected
DelayedRunnable
(long timestamp) Creates a new task to be executed at the given time. -
Method Summary
-
Field Details
-
timestamp
final long timestampTime of execution of this task, in nanoseconds provided bySystem.nanoTime()
. In the particular case of theDelayedRunnable.Immediate
subclass, the meaning of this field is modified: it is rather an ordinal value used for preserving task order.Note: we useSystem.nanoTime()
instead ofSystem.currentTimeMillis()
because the latter is not guaranteed to be monotonic:currentTimeMillis
may change abruptly for example if the user adjusts the clock of his operating system.
-
-
Constructor Details
-
DelayedRunnable
Creates a new task to be executed after the given delay.- Parameters:
delay
- delay before execution of this task.unit
- unit of measurement of givendelay
.
-
DelayedRunnable
protected DelayedRunnable(long timestamp) Creates a new task to be executed at the given time. It is user's responsibility to add theSystem.nanoTime()
value to the delay (s)he wants to wait.- Parameters:
timestamp
- time of execution of this task, in nanoseconds relative toSystem.nanoTime()
.
-
-
Method Details
-
getDelay
Returns the delay to wait before to execute this task, or0
if this task shall be executed immediately. -
compareTo
Compares this task with the given delayed object for ordering. Theother
object shall be an instance ofDelayedRunnable
. This restriction should be okay since theDelayedExecutor
queue accepts onlyDelayedRunnable
instances.- Specified by:
compareTo
in interfaceComparable<Delayed>
- Parameters:
other
- the other delayed object to compare with this delayed task.- Returns:
- -1 if the other task should happen before this one, +1 if it should happen after, or 0.
-