Class AbstractThreadManager

java.lang.Object
com.pnfsoftware.jeb.util.concurrent.AbstractThreadManager
Direct Known Subclasses:
DaemonThreadManager

public abstract class AbstractThreadManager extends Object
A non-static, customizable version of ThreadUtil.
  • Constructor Details

    • AbstractThreadManager

      public AbstractThreadManager()
  • Method Details

    • create

      public abstract Thread create(Runnable r)
      Create a thread.
      Parameters:
      r - the runnable
      Returns:
      the new thread
    • start

      public Thread start(Runnable r)
      Create and start a new daemon thread.
      Parameters:
      r - the runnable
      Returns:
      the running thread
    • start

      public Thread start(String name, Runnable r)
      Create and start a new daemon thread.
      Parameters:
      name - thread name
      r - the runnable
      Returns:
      the running thread
    • stop

      public boolean stop(Thread t)
      Gracefully stop a running thread. This method is blocking.
      Parameters:
      t - the running thread
      Returns:
      true if the thread was stopped successfully
    • monitor

      public boolean monitor(Thread t, IMonitorInfoProvider provider)
      Monitor a running thread, and attempt to terminate it after a dynamic timeout has elapsed. This method is blocking. In order for this method to work properly and responsively, the monitored thread should check for interruptions regularly, and should not disregard InterruptedExceptions.
      Parameters:
      t - the running thread
      provider - information for the monitor (timeout, probingPeriod, etc.); if the probing period is invalid, it will be set to a default 100ms.
      Returns:
      true if the thread has ended successfully (may have ended because it completed, may have ended because it processed the interruption); unless something bad happens (eg, the monitor is interrupted), this method should always return true