public final class BackoffIdleStrategy extends java.lang.Object implements IdleStrategy
| Modifier and Type | Field and Description |
|---|---|
protected long |
maxParkPeriodNs |
protected long |
maxSpins |
protected long |
maxYields |
protected long |
minParkPeriodNs |
protected long |
parkPeriodNs |
protected long |
spins |
protected org.agrona.concurrent.BackoffIdleStrategyData.State |
state |
protected long |
yields |
| Constructor and Description |
|---|
BackoffIdleStrategy(long maxSpins,
long maxYields,
long minParkPeriodNs,
long maxParkPeriodNs)
Create a set of state tracking idle behavior
|
| Modifier and Type | Method and Description |
|---|---|
void |
idle()
Perform current idle action (e.g.
|
void |
idle(int workCount)
Perform current idle action (e.g.
|
void |
reset()
Reset the internal state in preparation for entering an idle state again.
|
protected final long maxSpins
protected final long maxYields
protected final long minParkPeriodNs
protected final long maxParkPeriodNs
protected org.agrona.concurrent.BackoffIdleStrategyData.State state
protected long spins
protected long yields
protected long parkPeriodNs
public BackoffIdleStrategy(long maxSpins,
long maxYields,
long minParkPeriodNs,
long maxParkPeriodNs)
maxSpins - to perform before moving to Thread.yield()maxYields - to perform before moving to LockSupport.parkNanos(long)minParkPeriodNs - to use when initiating parkingmaxParkPeriodNs - to use when parkingpublic void idle(int workCount)
while (isRunning)
{
idleStrategy.idle(doWork());
}
idle in interface IdleStrategyworkCount - performed in last duty cycle.public void idle()
IdleStrategyIdleStrategy.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()
IdleStrategyreset in interface IdleStrategyCopyright © 2014 - 2016 Real Logic Ltd. All Rights Reserved.