Package com.atlassian.bamboo.executor
Class InterruptThreadWatchdog
- java.lang.Object
-
- com.atlassian.bamboo.executor.InterruptThreadWatchdog
-
- All Implemented Interfaces:
org.apache.tools.ant.util.TimeoutObserver
@ThreadSafe public abstract class InterruptThreadWatchdog extends Object implements org.apache.tools.ant.util.TimeoutObserver
An abstract class for interrupting a thread after a given timeout.onBeforeInterrupt(Thread)
is for implementors adding logical logging comments
-
-
Constructor Summary
Constructors Constructor Description InterruptThreadWatchdog(long timeoutSeconds, @NotNull Thread thread)
Creates a new watchdog with a given timeoutSeconds.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description long
getTimeoutSeconds()
boolean
isThreadInterrupted()
Indicates whether the thread run was killed on timeoutSeconds or not.protected abstract void
onBeforeInterrupt(Thread thread)
Forced extension point, usually would just have some intelligent logging.void
start()
Watches the given process and terminates it, if it runs for too long.void
stop()
Stops the watcher.void
timeoutOccured(org.apache.tools.ant.util.Watchdog w)
Called after watchdog has finished.
-
-
-
Constructor Detail
-
InterruptThreadWatchdog
public InterruptThreadWatchdog(long timeoutSeconds, @NotNull @NotNull Thread thread)
Creates a new watchdog with a given timeoutSeconds.- Parameters:
timeoutSeconds
- the timeout for the thread in seconds. It must be greater than 0.thread
-
-
-
Method Detail
-
start
public void start()
Watches the given process and terminates it, if it runs for too long. All information from the previous run are reset.- Throws:
IllegalStateException
- if a process is still being monitored.
-
stop
public void stop()
Stops the watcher. It will notify all threads possibly waiting on this object.
-
timeoutOccured
public void timeoutOccured(org.apache.tools.ant.util.Watchdog w)
Called after watchdog has finished. This can be called in the watchdog thread- Specified by:
timeoutOccured
in interfaceorg.apache.tools.ant.util.TimeoutObserver
- Parameters:
w
- the watchdog
-
onBeforeInterrupt
protected abstract void onBeforeInterrupt(Thread thread)
Forced extension point, usually would just have some intelligent logging. Will run under synchronization- Parameters:
thread
-
-
isThreadInterrupted
public boolean isThreadInterrupted()
Indicates whether the thread run was killed on timeoutSeconds or not.- Returns:
- true if the process was killed otherwise false.
-
getTimeoutSeconds
public long getTimeoutSeconds()
-
-