@ThreadSafe public final class HeartbeatScheduler extends Object
await(String)
method can be used to wait for a thread to start
waiting to be scheduled and the schedule(String)
method can be used to schedule a thread
that is waiting to be scheduled.
The contract of this class is that the schedule(String)
method should only be called for
threads that are in fact waiting to be scheduled. If this contract is not met, concurrent
execution of a thread and the heartbeat scheduler logic to schedule the thread can lead to a
deadlock.
For an example of how to use the HeartbeatScheduler
, see unit test of
HeartbeatThread
.Modifier and Type | Method and Description |
---|---|
static void |
addTimer(ScheduledTimer timer) |
static void |
await(String name)
Waits for the given thread to be ready to be scheduled.
|
static void |
await(String name,
long time,
TimeUnit unit)
Waits until the given thread can be executed, throwing an unchecked exception of the given
timeout expires.
|
static void |
clearTimer(String name)
Removes a timer name from the scheduler if it exists.
|
static void |
execute(String name)
Convenience method for executing a heartbeat and waiting for it to complete.
|
static Set<String> |
getThreadNames() |
static void |
removeTimer(ScheduledTimer timer)
Removes a timer from the scheduler.
|
static void |
schedule(String threadName)
Schedules execution of a heartbeat for the given thread.
|
public static void addTimer(ScheduledTimer timer)
timer
- a timer to add to the schedulerpublic static void clearTimer(String name)
name
- the name to clearpublic static void removeTimer(ScheduledTimer timer)
timer
- the timer to removepublic static Set<String> getThreadNames()
public static void schedule(String threadName)
threadName
- a name of the thread for which heartbeat is to be executedpublic static void await(String name) throws InterruptedException
name
- a name of the thread to wait forInterruptedException
- if the waiting thread is interruptedpublic static void await(String name, long time, TimeUnit unit) throws InterruptedException
name
- a name of the thread to wait fortime
- the maximum time to waitunit
- the time unit of the time
argumentInterruptedException
- if the waiting thread is interruptedpublic static void execute(String name) throws InterruptedException
name
- the name of the heartbeat to executeInterruptedException
- if the waiting thread is interruptedCopyright © 2023. All Rights Reserved.