Top Fields Constructors Methods
org.reactfx

pack-priv Class ScheduledExecutorServiceTimer

extends Object
implements Timer
Class Inheritance
All Implemented Interfaces
org.reactfx.util.Timer
Imports
java.util.concurrent.Executor, .ScheduledExecutorService, .ScheduledFuture, .TimeUnit, org.reactfx.util.Timer, .TriFunction

Field Summary

Modifier and TypeField and Description
private final Runnable
private final Executor
private ScheduledFuture<?>
private final TriFunction<Long, TimeUnit, Runnable, ScheduledFuture<?>>
private long
private final long
private final TimeUnit

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Timer
create(Duration timeout, Runnable action, ScheduledExecutorService scheduler, Executor eventThreadExecutor)

public static Timer
createPeriodic(Duration timeout, Runnable action, ScheduledExecutorService scheduler, Executor eventThreadExecutor)

public final void
restart()

Implements org.reactfx.util.Timer.restart.

Schedules the associated action to be executed after the associated delay.

public final void
stop()

Implements org.reactfx.util.Timer.stop.

If the associated action has been scheduled for execution but not yet executed, this method prevents it from being executed at all.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

actionback to summary
private final Runnable action
eventThreadExecutorback to summary
private final Executor eventThreadExecutor
pendingTimerback to summary
private ScheduledFuture<?> pendingTimer
schedulerback to summary
private final TriFunction<Long, TimeUnit, Runnable, ScheduledFuture<?>> scheduler
seqback to summary
private long seq
timeoutback to summary
private final long timeout
unitback to summary
private final TimeUnit unit

Constructor Detail

ScheduledExecutorServiceTimerback to summary
private ScheduledExecutorServiceTimer(Duration timeout, Runnable action, TriFunction<Long, TimeUnit, Runnable, ScheduledFuture<?>> scheduler, Executor eventThreadExecutor)

Method Detail

createback to summary
public static Timer create(Duration timeout, Runnable action, ScheduledExecutorService scheduler, Executor eventThreadExecutor)
createPeriodicback to summary
public static Timer createPeriodic(Duration timeout, Runnable action, ScheduledExecutorService scheduler, Executor eventThreadExecutor)
restartback to summary
public final void restart()

Implements org.reactfx.util.Timer.restart.

Doc from org.reactfx.util.Timer.restart.

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.

Annotations
@Override
stopback to summary
public final void stop()

Implements org.reactfx.util.Timer.stop.

Doc from org.reactfx.util.Timer.stop.

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 by javafx.animation.Animation#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

In contrast, using the FxTimer, the action is guaranteed not to be executed after stop():
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

Annotations
@Override