Class MonitoredThread

  • All Implemented Interfaces:
    java.lang.Runnable

    public class MonitoredThread
    extends java.lang.Thread
    Thread class used by MonitoredThreadPoolExecutor, contains additional state about the thread to monitor thread behavior.
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.lang.Thread

        java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean borrowed
      Flag if the thread was borrowed.
      protected long departure
      Departure time of the thread from the pool.
      protected int number
      The thread number assigned to the thread.
      protected MonitoredThreadPoolExecutor origin
      Thread pool executor that created the thread.
      • Fields inherited from class java.lang.Thread

        MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void borrow()
      Notify the pool that the thread is borrowed and return the return to the pool is expected to be delayed.
      long getDeparture()
      Gets the time the thread departed from the pool.
      int getNumber()
      Gets the thread number.
      boolean isBlocked()
      Returns if the thread is currently blocked.
      boolean isBorrowed()
      Returns if the thread is currently borrowed.
      void setDeparture​(long departure)
      Sets the time the thread departed from the pool.
      void setNumber​(int num)
      Sets the thread number.
      static void tryBorrow()
      Try to borrow the thread.
      • Methods inherited from class java.lang.Thread

        activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • number

        protected int number
        The thread number assigned to the thread.
      • departure

        protected volatile long departure
        Departure time of the thread from the pool.
      • borrowed

        protected volatile boolean borrowed
        Flag if the thread was borrowed.
    • Constructor Detail

      • MonitoredThread

        public MonitoredThread​(java.lang.Runnable r,
                               MonitoredThreadPoolExecutor origin)
        Creates the thread.
        Parameters:
        r - The runnable to execute.
        origin - The originating thread pool.
    • Method Detail

      • getNumber

        public int getNumber()
        Gets the thread number.
        Returns:
        The thread number.
      • setNumber

        public void setNumber​(int num)
        Sets the thread number.
        Parameters:
        num - The thread number.
      • getDeparture

        public long getDeparture()
        Gets the time the thread departed from the pool.
        Returns:
        The time the thread departed from the pool.
      • setDeparture

        public void setDeparture​(long departure)
        Sets the time the thread departed from the pool.
        Parameters:
        departure - The time the thread departed from the pool.
      • borrow

        protected void borrow()
        Notify the pool that the thread is borrowed and return the return to the pool is expected to be delayed.
      • isBorrowed

        public boolean isBorrowed()
        Returns if the thread is currently borrowed.
        Returns:
        True, if borrowed.
      • isBlocked

        public boolean isBlocked()
        Returns if the thread is currently blocked.
        Returns:
        True, if blocked.
      • tryBorrow

        public static final void tryBorrow()
        Try to borrow the thread. If thread is non-monitored, this does nothing.