@ThreadSafe public final class ScheduledTimer extends Object implements HeartbeatTimer
ScheduledTimer
blocks on the tick()
method, waiting for
someone to invoke the schedule()
method.
The contract of this class is that the schedule()
method should only be called after the
tick()
was called and that there is exactly one schedule()
call per
tick()
call.
The schedule()
method is not meant to be invoked directly. Instead, the
HeartbeatScheduler
class should be used.Constructor and Description |
---|
ScheduledTimer(String threadName,
java.time.Clock clock,
java.util.function.Supplier<SleepIntervalSupplier> intervalSupplierSupplier)
Creates a new instance of
ScheduledTimer . |
Modifier and Type | Method and Description |
---|---|
String |
getThreadName() |
protected void |
schedule()
Schedules execution of the heartbeat.
|
long |
tick()
Waits until next heartbeat should be executed.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
update
public ScheduledTimer(String threadName, java.time.Clock clock, java.util.function.Supplier<SleepIntervalSupplier> intervalSupplierSupplier)
ScheduledTimer
.threadName
- the thread nameclock
- for telling the current time (unused)intervalSupplierSupplier
- Sleep time between different heartbeat supplierpublic String getThreadName()
protected void schedule()
public long tick() throws InterruptedException
HeartbeatTimer
tick
in interface HeartbeatTimer
InterruptedException
- if the thread is interrupted while waitingCopyright © 2023. All Rights Reserved.