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 Details

    • 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 Details

    • 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 interface org.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()