@ThreadSafe
public final class SnoozeAlarm
extends Object
Allows sleepy threads to take a nap until either a specified amount of time has elapsed or something happened that required everybody to wake up.
Each instance can control any number of threads. A wakeUp() call
will affect all the threads snoozing on the same instance.
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_MINIMUM_SNOOZE_MILLIS
Minimum snooze time in milliseconds.
|
static String |
MINIMUM_SNOOZE_MILLIS_PROPERTY
Minimum snooze millis system property.
|
| Constructor and Description |
|---|
SnoozeAlarm()
Constructs an instance.
|
SnoozeAlarm(Optional<Object> sync)
Constructs an instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes.
|
void |
snooze()
Snoozes until awoken.
|
boolean |
snooze(ElapsedTime snoozeTime)
Snoozes for the specified time.
|
boolean |
snooze(Optional<DateTime> wakeTime)
Snoozes until the specified time.
|
static boolean |
validate(ElapsedTime time,
Object caller,
Messages.Entry nameEntry)
Validates a snooze time.
|
void |
wakeUp()
Wakes up all snoozers.
|
public static final String DEFAULT_MINIMUM_SNOOZE_MILLIS
public static final String MINIMUM_SNOOZE_MILLIS_PROPERTY
public SnoozeAlarm()
public SnoozeAlarm(@Nonnull
Optional<Object> sync)
This constructor allows the specification of a synchronization object (defaults to the created instance) to solve some deadlock problems.
sync - A sync object (when null, will be this).@CheckReturnValue
public static boolean validate(@Nonnull
ElapsedTime time,
@Nonnull
Object caller,
@Nonnull
Messages.Entry nameEntry)
time - The snooze time.caller - The caller.nameEntry - The entry for an identifying name for the error message.public void close()
Also wakes up the snoozers.
public void snooze()
throws InterruptedException
Caution: calling this method while holding a lock other than the sync object supplied to the constructor might cause a stall.
InterruptedException - When interrupted.@CheckReturnValue
public boolean snooze(@Nonnull
ElapsedTime snoozeTime)
throws InterruptedException
Caution: calling this method while holding a lock other than the sync object supplied to the constructor might cause a stall.
snoozeTime - The snooze time.InterruptedException - When interrupted.@CheckReturnValue
public boolean snooze(@Nonnull
Optional<DateTime> wakeTime)
throws InterruptedException
Caution: calling this method while holding a lock other than the sync object supplied to the constructor may cause a stall.
wakeTime - The wake time (empty for infinite).InterruptedException - When interrupted.public void wakeUp()
Copyright © 2003-2019 Serge Brisson. All Rights Reserved.