public final class ControllableIdleStrategy extends Object implements 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 ThreadHints.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.| Modifier and Type | Field and Description |
|---|---|
static String |
ALIAS
Name to be returned from
alias(). |
static int |
BUSY_SPIN
Apply
BusySpinIdleStrategy. |
static int |
NOOP
Apply
NoOpIdleStrategy. |
static int |
NOT_CONTROLLED
Not controlled so will go with default of
PARK. |
static int |
PARK
Apply
SleepingIdleStrategy with minimum sleep interval. |
static int |
YIELD
Apply
YieldingIdleStrategy. |
| Constructor and Description |
|---|
ControllableIdleStrategy(StatusIndicatorReader statusIndicator)
Configure idle strategy taking an indicator of which strategy should be applied.
|
| Modifier and Type | Method and Description |
|---|---|
String |
alias()
Simple name by which the strategy can be identified.
|
void |
idle()
Perform current idle action (e.g.
|
void |
idle(int workCount)
Idle based on current status indication value
|
void |
reset()
Reset the internal state in preparation for entering an idle state again.
|
String |
toString() |
public static final String ALIAS
alias().public static final int NOT_CONTROLLED
PARK.public static final int NOOP
NoOpIdleStrategy.public static final int BUSY_SPIN
BusySpinIdleStrategy.public static final int YIELD
YieldingIdleStrategy.public static final int PARK
SleepingIdleStrategy with minimum sleep interval.public ControllableIdleStrategy(StatusIndicatorReader statusIndicator)
statusIndicator - indicator of which strategy should be applied.public void idle(int workCount)
idle in interface IdleStrategyworkCount - performed in last duty cycle.IdleStrategy.idle(int)public void idle()
IdleStrategy.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();
}
idle in interface IdleStrategypublic void reset()
reset in interface IdleStrategypublic String alias()
alias in interface IdleStrategyCopyright © 2014-2020 Real Logic Limited. All Rights Reserved.