BackoffIdleStrategy extends BackoffIdleStrategyData implements IdleStrategy { @Override public boolean idle () { switch ( state ) { case NOT_IDLE: state = State.SPINNING; idle++; break; case SPINNING: ThreadHints.onSpinWait(); if ( ++idle > maxSpins ) { state = State.YIELDING; } break; case YIELDING: if ( ++idle > maxYields ) { state = State.PARKING; parkPeriodNs = minParkPeriodNs; } else { Thread.yield(); } break; case PARKING: LockSupport.parkNanos( parkPeriodNs ); parkPeriodNs = min( parkPeriodNs << 1, maxParkPeriodNs ); return ++idle > maxParks; } return false; } BackoffIdleStrategy( final long maxSpins,
                          final long maxYields,
                          final long maxParks,
                          final long minParkPeriodNs,
                          final long maxParkPeriodNs ); static BackoffIdleStrategy newDefaultInstance(); @Override boolean idle(); @Override void reset();  }
@Test public void testIdle () { assertEquals( State.NOT_IDLE, idleStrategy.getState() ); assertFalse( idleStrategy.idle() ); assertEquals( State.SPINNING, idleStrategy.getState() ); assertFalse( idleStrategy.idle() ); assertEquals( State.SPINNING, idleStrategy.getState() ); assertFalse( idleStrategy.idle() ); assertEquals( State.YIELDING, idleStrategy.getState() ); assertFalse( idleStrategy.idle() ); assertEquals( State.YIELDING, idleStrategy.getState() ); assertFalse( idleStrategy.idle() ); assertEquals( State.YIELDING, idleStrategy.getState() ); assertFalse( idleStrategy.idle() ); assertEquals( State.PARKING, idleStrategy.getState() ); assertFalse( idleStrategy.idle() ); assertEquals( State.PARKING, idleStrategy.getState() ); assertFalse( idleStrategy.idle() ); assertEquals( State.PARKING, idleStrategy.getState() ); assertFalse( idleStrategy.idle() ); assertEquals( State.PARKING, idleStrategy.getState() ); assertTrue( idleStrategy.idle() ); assertEquals( State.PARKING, idleStrategy.getState() ); assertTrue( idleStrategy.idle() ); }