public final class BackoffIdleStrategy extends java.lang.Object implements IdleStrategy
Spin for maxSpins, then
Thread.yield()
for maxYields, then
LockSupport.parkNanos(long)
on an exponential backoff to maxParkPeriodNs
Modifier and Type | Field and Description |
---|---|
protected long |
maxParkPeriodNs |
protected long |
maxSpins |
protected long |
maxYields |
protected long |
minParkPeriodNs |
protected static int |
NOT_IDLE |
protected static int |
PARKING |
protected long |
parkPeriodNs |
protected static int |
SPINNING |
protected long |
spins |
protected int |
state |
protected static int |
YIELDING |
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.
|
java.lang.String |
toString() |
protected static final int NOT_IDLE
protected static final int SPINNING
protected static final int YIELDING
protected static final int PARKING
protected final long maxSpins
protected final long maxYields
protected final long minParkPeriodNs
protected final long maxParkPeriodNs
protected int 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)
Callers are expected to follow this pattern:
while (isRunning)
{
idleStrategy.idle(doWork());
}
idle
in interface IdleStrategy
workCount
- performed in last duty cycle.public void idle()
IdleStrategy
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 IdleStrategy
public void reset()
IdleStrategy
reset
in interface IdleStrategy
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2014-2018 Real Logic Ltd. All Rights Reserved.