public class MilliPauser extends Object implements Pauser
Pauser implementation that provides precise control over thread pausing based on a specified duration in milliseconds.
This pauser can operate both synchronously and asynchronously, providing flexibility in thread management.Pauser.SleepyWarningBALANCED, MIN_BUSY, MIN_PROCESSORS, SLEEPY| Constructor and Description |
|---|
MilliPauser(long pauseTimeMS)
Constructs a new
MilliPauser with a specified pause time in milliseconds. |
| Modifier and Type | Method and Description |
|---|---|
void |
asyncPause()
Initiates an asynchronous pause that will last for the previously set pause duration.
|
boolean |
asyncPausing()
Checks if the pauser is currently in an asynchronous pausing state.
|
long |
countPaused()
Returns the number of times this pauser has been activated to pause the thread.
|
MilliPauser |
minPauseTimeMS(long pauseTimeMS)
Sets the pause time to the minimum of the current or specified duration in milliseconds.
|
void |
pause()
Pauses the current thread for the configured duration using millisecond precision.
|
void |
pause(long timeout,
@NotNull TimeUnit timeUnit)
Pauses the current thread for a specified duration in milliseconds.
|
long |
pauseTimeMS()
Retrieves the current pause time in milliseconds.
|
MilliPauser |
pauseTimeMS(long pauseTimeMS)
Sets the pause time to a specified duration in milliseconds.
|
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, measured in milliseconds.
|
String |
toString()
Provides a string representation of this pauser, identifying the configured pause time.
|
void |
unpause()
Unpauses the currently paused thread if it is in a paused state.
|
public MilliPauser(long pauseTimeMS)
MilliPauser with a specified pause time in milliseconds.pauseTimeMS - the pause time for each pause operation, in millisecondspublic MilliPauser pauseTimeMS(long pauseTimeMS)
pauseTimeMS - the new pause time in millisecondsMilliPauser instance for chainingpublic MilliPauser minPauseTimeMS(long pauseTimeMS)
pauseTimeMS - the proposed minimum pause time in millisecondsMilliPauser instance for chainingpublic long pauseTimeMS()
public 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 Pausertimeout - the maximum time to pause in the specified timeUnittimeUnit - the unit of time for timeoutTimeoutException - if the pause operation is not completed within the specified timeoutpublic void unpause()
public long timePaused()
timePaused in interface Pauserpublic long countPaused()
countPaused in interface PauserCopyright © 2024. All rights reserved.