public class LongPauser extends Object implements Pauser, TimingPauser
Pauser that implements a pausing strategy with phases of busy waiting, yielding, and sleeping,
with each phase increasing in duration up to a configured limit. It is designed for scenarios where a gradual
back-off is needed from active to more passive waiting states.
The pausing behavior begins with busy waiting, transitions to yielding, and ultimately moves to sleeping, progressively increasing the pause time from a minimum to a specified maximum duration.
Pauser.SleepyWarningBALANCED, MIN_BUSY, MIN_PROCESSORS, SLEEPY| Constructor and Description |
|---|
LongPauser(int minBusy,
int minYield,
long minTime,
long maxTime,
@NotNull TimeUnit timeUnit)
first it will busy wait, then it will yield, then sleep for a small amount of time, then
increases to a large amount of time.
|
| Modifier and Type | Method and Description |
|---|---|
void |
asyncPause()
Initiates an asynchronous pause that will last for the current phase's duration.
|
boolean |
asyncPausing()
Checks if the pauser is currently in an asynchronous pausing state.
|
long |
countPaused()
Returns the total number of pauses that have been initiated.
|
void |
pause()
Pauses the current thread according to the phased pausing strategy.
|
void |
pause(long timeout,
@NotNull TimeUnit timeUnit)
Implementation of the pause method for the LongPauser.
|
void |
reset()
Resets the pauser's internal state back (if any) to the most aggressive setting.
|
long |
timePaused()
Returns the total time that the thread has been paused, in milliseconds.
|
String |
toString()
Provides a human-readable description of the pauser's configuration.
|
void |
unpause()
Try to cancel the pausing if it is pausing.
|
public LongPauser(int minBusy,
int minYield,
long minTime,
long maxTime,
@NotNull
@NotNull TimeUnit timeUnit)
minBusy - the length in timeUnit to go around doing nothing, after this is
reached it will then start to yieldminYield - the length in timeUnit it will yield, before it starts to sleepminTime - the amount of time to sleep ( initially )maxTime - the amount of time subsequently to sleeptimeUnit - the unit of the minTime and maxTimepublic void reset()
PauserPausers that progressively increases the pause time are reset back to its lowest pause time.
Call this if you just did some work.
public void pause()
public void asyncPause()
asyncPause in interface PauserPauser.asyncPausing()public boolean asyncPausing()
asyncPausing in interface Pausertrue if still in the pausing state, false otherwisepublic void pause(long timeout,
@NotNull
@NotNull TimeUnit timeUnit)
throws TimeoutException
pause in interface Pauserpause in interface TimingPausertimeout - The maximum time duration to wait before throwing a TimeoutException.timeUnit - The unit of the timeout parameter.TimeoutException - If the pause exceeds the specified timeout.public void unpause()
PauserNo guarantee is made that this call will actually have an effect.
public long timePaused()
timePaused in interface Pauserpublic long countPaused()
countPaused in interface PauserCopyright © 2024. All rights reserved.