Package io.github.ai4ci.util
Class PauseableThread
java.lang.Object
java.lang.Thread
io.github.ai4ci.util.PauseableThread
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
SimulationExecutor
,SimulationFactory
A pauseable daemon thread which will can be required to go into a waiting
state after each execution of the loop. This is basically a thread which
executes a while loop, with pause, resume and halt functions.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract void
doLoop()
Repeatedly called while the thread is not paused or halting.void
halt()
abstract boolean
Signify the thread loop is complete and proceed to shutdown.boolean
void
pause()
Threads can pause themselves but will never unpause (unless halting).void
run()
abstract void
setup()
Run on thread once at the start.abstract void
shutdown
(boolean completedNormally) Shutdown the thread.status()
void
unpause()
Non blocking unpause a thread.Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
Constructor Details
-
PauseableThread
protected PauseableThread() -
PauseableThread
-
-
Method Details
-
isWaiting
public boolean isWaiting() -
halt
public void halt() -
pause
public void pause()Threads can pause themselves but will never unpause (unless halting). If the thread is complete this does nothing. -
unpause
public void unpause()Non blocking unpause a thread. Nothing happens if the thread is not paused. Otherwise the thread will be woken up and resume executing doLoop() repeatedly, until isComplete() is true, or told to halt. -
run
public void run() -
status
-
setup
public abstract void setup()Run on thread once at the start. Can setup thread local resources. Constructor can be used to set up shared resources. -
doLoop
public abstract void doLoop()Repeatedly called while the thread is not paused or halting. This can interact with resources shared with other threads but needs to be synchronised on them (or use non blocking). This operates equivalent to a `while (!isComplete()) {doLoop();}` -
isComplete
public abstract boolean isComplete()Signify the thread loop is complete and proceed to shutdown. This is checked even if the thread is paused. -
shutdown
public abstract void shutdown(boolean completedNormally) Shutdown the thread. This must close down any resources and exit without error.- Parameters:
completedNormally
- did the loop complete or was the thread halted?
-