Class ThreadMonitor
java.lang.Object
com.pnfsoftware.jeb.util.concurrent.ThreadMonitor
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.-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionThreadMonitor(Thread thread, IMonitorInfoProvider moninfo, Runnable before, Runnable after) Create a new thread monitor instance. -
Method Summary
Modifier and TypeMethodDescriptionGet the monitored thread.getState()Get the current monitor state.booleanDetermine whether monitoring is in progress.booleanisReady()Determine whether the monitor has not started yet.booleanDetermine whether monitoring has ended.voidstart(boolean blocking) Start monitoring the target thread.
-
Constructor Details
-
ThreadMonitor
Create a new thread monitor instance.- Parameters:
thread- the non-started thread object to be monitoredmoninfo- information for the monitorbefore- optional routine run before monitoring occursafter- optional routine run after monitoring is done
-
-
Method Details
-
getMonitoredThread
Get the monitored thread.- Returns:
- the thread passed to the constructor
-
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
-