public class SingleWaiterCooperativeNotifier extends SingleWaiterMultiNotifier
Unlike the standard Notifier usage, a signaling thread must at some point invoke the static flush() method, or await(long) on any SingleWaiterCooperativeNotifier to ensure that all deferred signals are processed.
| Modifier and Type | Field and Description |
|---|---|
protected Thread |
m_threadAwait
The waiting thread, or null.
|
protected static byte |
s_cSignal
An intentionally non-volatile signal counter to ensure periodic flushes.
|
m_oState| Constructor and Description |
|---|
SingleWaiterCooperativeNotifier() |
| Modifier and Type | Method and Description |
|---|---|
void |
await(long cMillis)
Wait for a notification (which may have already occurred).
|
protected void |
consumeSignal()
Consume the signal.
|
static void |
flush()
Ensure that any deferred signals will be processed.
|
protected static void |
flush(int cWake, SingleWaiterCooperativeNotifier self)
Ensure that any deferred signals will be processed.
|
void |
signal()
Notifies the waiting thread(s), waking them up if awaiting, or preventing the next thread from going to sleep on the next await attempt.
|
String |
toString() |
await, getWaitingThread, signalInternalprotected Thread m_threadAwait
protected static byte s_cSignal
public static void flush()
Note it is more advantageous if the calling thread's natural idle point is to sit in await(long), in which case calling this method is not required.
public void await(long cMillis)
throws InterruptedException
Notifierawait in interface Notifierawait in class SingleWaiterMultiNotifiercMillis - the maximum wait time in milliseconds, or zero for indefiniteInterruptedException - if the calling thread is interrupted while it is waitingpublic void signal()
Notifiersignal in interface Notifiersignal in class SingleWaiterMultiNotifierpublic String toString()
toString in class SingleWaiterMultiNotifier
protected static void flush(int cWake,
SingleWaiterCooperativeNotifier self)
cWake - the number of deferrals to signal on the calling threadself - the waiting notifier which is flushing, or nullprotected void consumeSignal()
SingleWaiterMultiNotifierconsumeSignal in class SingleWaiterMultiNotifier