Package org.reactfx
Class ScheduledExecutorServiceTimer
java.lang.Object
org.reactfx.ScheduledExecutorServiceTimer
- All Implemented Interfaces:
Timer
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Runnable
private final Executor
private ScheduledFuture
<?> private final TriFunction
<Long, TimeUnit, Runnable, ScheduledFuture<?>> private long
private final long
private final TimeUnit
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
ScheduledExecutorServiceTimer
(Duration timeout, Runnable action, TriFunction<Long, TimeUnit, Runnable, ScheduledFuture<?>> scheduler, Executor eventThreadExecutor) -
Method Summary
Modifier and TypeMethodDescriptionstatic Timer
create
(Duration timeout, Runnable action, ScheduledExecutorService scheduler, Executor eventThreadExecutor) static Timer
createPeriodic
(Duration timeout, Runnable action, ScheduledExecutorService scheduler, Executor eventThreadExecutor) final void
restart()
Schedules the associated action to be executed after the associated delay.final void
stop()
If the associated action has been scheduled for execution but not yet executed, this method prevents it from being executed at all.
-
Field Details
-
timeout
private final long timeout -
unit
-
action
-
scheduler
-
eventThreadExecutor
-
pendingTimer
-
seq
private long seq
-
-
Constructor Details
-
ScheduledExecutorServiceTimer
private ScheduledExecutorServiceTimer(Duration timeout, Runnable action, TriFunction<Long, TimeUnit, Runnable, ScheduledFuture<?>> scheduler, Executor eventThreadExecutor)
-
-
Method Details
-
create
public static Timer create(Duration timeout, Runnable action, ScheduledExecutorService scheduler, Executor eventThreadExecutor) -
createPeriodic
public static Timer createPeriodic(Duration timeout, Runnable action, ScheduledExecutorService scheduler, Executor eventThreadExecutor) -
restart
public final void restart()Description copied from interface:Timer
Schedules the associated action to be executed after the associated delay. If the action is already scheduled but hasn't been executed yet, the timeout is reset, so that the action won't be executed before the full delay from now. -
stop
public final void stop()Description copied from interface:Timer
If the associated action has been scheduled for execution but not yet executed, this method prevents it from being executed at all. This is also true in case the timer's timeout has already expired, but the associated action hasn't had a chance to be executed on the associated thread. Note that this is a stronger guarantee than the one given byAnimation.stop()
:Timeline timeline = new Timeline(new KeyFrame( Duration.millis(1000), ae -> System.out.println("FIRED ANYWAY"))); timeline.play(); // later on the JavaFX application thread, // but still before the action has been executed timeline.stop(); // later, "FIRED ANYWAY" may still be printed
FxTimer
, the action is guaranteed not to be executed afterstop()
:Timer timer = FxTimer.runLater( Duration.ofMillis(1000), () -> System.out.println("FIRED")); // later on the JavaFX application thread, // but still before the action has been executed timer.stop(); // "FIRED" is guaranteed *not* to be printed
-