Package com.oracle.coherence.common.base
Class SingleWaiterCooperativeNotifier
java.lang.Object
com.oracle.coherence.common.base.SingleWaiterMultiNotifier
com.oracle.coherence.common.base.SingleWaiterCooperativeNotifier
- All Implemented Interfaces:
Notifier
SingleWaiterCooperativeNotifier is an extension of the SingleWaiterMultiNotifier which attempts to offload
potentially expensive "notification" work from signaling threads onto the waiting threads. This notifier
is beneficial when there are few signaling threads, but potentially many waiting threads, each waiting on
their own notifier.
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.
- Author:
- mf 2014.03.12
-
Field Summary
Modifier and TypeFieldDescriptionprotected Thread
The waiting thread, or null.protected static byte
An intentionally non-volatile signal counter to ensure periodic flushes.Fields inherited from class com.oracle.coherence.common.base.SingleWaiterMultiNotifier
m_oState
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
await
(long cMillis) Wait for a notification.protected void
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.toString()
Methods inherited from class com.oracle.coherence.common.base.SingleWaiterMultiNotifier
getWaitingThread, signalInternal
-
Field Details
-
m_threadAwait
The waiting thread, or null. Visibility ensured via super.m_oState writes. -
s_cSignal
protected static byte s_cSignalAn intentionally non-volatile signal counter to ensure periodic flushes. byte is used to allow for auto-flush on every 256 signals (rollover)
-
-
Constructor Details
-
SingleWaiterCooperativeNotifier
public SingleWaiterCooperativeNotifier()
-
-
Method Details
-
flush
public static void flush()Ensure that any deferred signals will be processed.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. -
await
Description copied from interface:Notifier
Wait for a notification. Note that spurious wake-ups are possible.- Specified by:
await
in interfaceNotifier
- Overrides:
await
in classSingleWaiterMultiNotifier
- Parameters:
cMillis
- the maximum wait time in milliseconds, or zero for indefinite- Throws:
InterruptedException
- if the calling thread is interrupted while it is waiting
-
signal
public void signal()Description copied from interface:Notifier
Notifies the waiting thread(s), waking them up if awaiting.- Specified by:
signal
in interfaceNotifier
- Overrides:
signal
in classSingleWaiterMultiNotifier
-
toString
- Overrides:
toString
in classSingleWaiterMultiNotifier
-
flush
Ensure that any deferred signals will be processed.- Parameters:
cWake
- the number of deferrals to signal on the calling threadself
- the waiting notifier which is flushing, or null
-
consumeSignal
protected void consumeSignal()Description copied from class:SingleWaiterMultiNotifier
Consume the signal.- Overrides:
consumeSignal
in classSingleWaiterMultiNotifier
-