Class PauseableThread

java.lang.Object
java.lang.Thread
io.github.ai4ci.util.PauseableThread
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
SimulationExecutor, SimulationFactory

public abstract class PauseableThread extends Thread
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.
  • Constructor Details

    • PauseableThread

      protected PauseableThread()
    • PauseableThread

      protected PauseableThread(String name, int priority)
  • 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()
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • status

      public String 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?