Class ThreadMonitor

java.lang.Object
com.pnfsoftware.jeb.util.concurrent.ThreadMonitor

public class ThreadMonitor extends Object
This class is used to monitor the execution of a target thread. That target thread thread can be forcefully stopped after a dynamic timeout has elapsed. The target thread should check for and respect interruption requests (details). The monitor itself can be executed as a separate thread.
  • Constructor Details

    • ThreadMonitor

      public ThreadMonitor(Thread thread, IMonitorInfoProvider moninfo, Runnable before, Runnable after)
      Create a new thread monitor instance.
      Parameters:
      thread - the non-started thread object to be monitored
      moninfo - information for the monitor
      before - optional routine run before monitoring occurs
      after - optional routine run after monitoring is done
  • Method Details

    • getMonitoredThread

      public Thread getMonitoredThread()
      Get the monitored thread.
      Returns:
      the thread passed to the constructor
    • getState

      public ThreadMonitor.State getState()
      Get the current monitor state.
      Returns:
      the current state
    • isReady

      public boolean isReady()
      Determine whether the monitor has not started yet.
      Returns:
      true if the monitor state is ThreadMonitor.State.READY
    • isMonitoring

      public boolean isMonitoring()
      Determine whether monitoring is in progress.
      Returns:
      true if the monitor state is ThreadMonitor.State.MONITORING
    • isTerminated

      public boolean isTerminated()
      Determine whether monitoring has ended.
      Returns:
      true if the monitor state is terminal
    • start

      public void start(boolean blocking)
      Start monitoring the target thread.
      Parameters:
      blocking - true to run monitoring in the current thread; false to run it on a daemon thread