Package org.agrona.concurrent
Class ControllableIdleStrategy
java.lang.Object
org.agrona.concurrent.ControllableIdleStrategy
- All Implemented Interfaces:
IdleStrategy
IdleStrategy which can be controlled by a counter so its mode of operation can be switched between
doing nothing (NOOP), busy spinning by calling Thread.onSpinWait(), yielding by calling
Thread.yield(), or sleeping for the minimum period by calling LockSupport.parkNanos(long) when
work count is zero, so it idles.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringName to be returned fromalias().static final intApplyBusySpinIdleStrategy.static final intApplyNoOpIdleStrategy.static final intNot controlled so will go with default ofPARK.static final intApplySleepingIdleStrategywith minimum sleep interval.static final intApplyYieldingIdleStrategy. -
Constructor Summary
ConstructorsConstructorDescriptionControllableIdleStrategy(StatusIndicatorReader statusIndicator) Configure idle strategy taking an indicator of which strategy should be applied. -
Method Summary
Modifier and TypeMethodDescriptionalias()Simple name by which the strategy can be identified.voididle()Perform current idle action (e.g.voididle(int workCount) Idle based on current status indication value.voidreset()Reset the internal state in preparation for entering an idle state again.toString()
-
Field Details
-
ALIAS
Name to be returned fromalias().- See Also:
-
NOT_CONTROLLED
public static final int NOT_CONTROLLEDNot controlled so will go with default ofPARK.- See Also:
-
NOOP
public static final int NOOPApplyNoOpIdleStrategy.- See Also:
-
BUSY_SPIN
public static final int BUSY_SPINApplyBusySpinIdleStrategy.- See Also:
-
YIELD
public static final int YIELDApplyYieldingIdleStrategy.- See Also:
-
PARK
public static final int PARKApplySleepingIdleStrategywith minimum sleep interval.- See Also:
-
-
Constructor Details
-
ControllableIdleStrategy
Configure idle strategy taking an indicator of which strategy should be applied.- Parameters:
statusIndicator- indicator of which strategy should be applied.
-
-
Method Details
-
idle
public void idle(int workCount) Idle based on current status indication value.- Specified by:
idlein interfaceIdleStrategy- Parameters:
workCount- performed in last duty cycle.- See Also:
-
idle
public void idle()Perform current idle action (e.g. nothing/yield/sleep). To be used in conjunction withIdleStrategy.reset()to clear internal state when idle period is over (or before it begins). Callers are expected to follow this pattern:while (isRunning) { if (!hasWork()) { idleStrategy.reset(); while (!hasWork()) { if (!isRunning) { return; } idleStrategy.idle(); } } doWork(); }- Specified by:
idlein interfaceIdleStrategy
-
reset
public void reset()Reset the internal state in preparation for entering an idle state again.- Specified by:
resetin interfaceIdleStrategy
-
alias
Simple name by which the strategy can be identified.- Specified by:
aliasin interfaceIdleStrategy- Returns:
- simple name by which the strategy can be identified.
-
toString
-