Class MonitoredThreadPoolExecutor

All Implemented Interfaces:
AutoCloseable, Executor, ExecutorService

public class MonitoredThreadPoolExecutor extends ThreadPoolExecutor
Thread pool executor based on the Java 5 ThreadPoolExecutor class. Uses a monitoring thread to monitor pool thread behavior to adjust pool size.
  • Field Details

    • DEBUG

      protected static final boolean DEBUG
      Print debug messages
      See Also:
    • AGGRESSIVE

      protected static final boolean AGGRESSIVE
      If true, be more aggressive when creating threads.
      See Also:
    • MONIT_THRESHOLD

      protected static final int MONIT_THRESHOLD
      Threshold for activating monitoring.
    • BASE_TCNT

      protected static final int BASE_TCNT
      Starting number of threads.
    • MONIT_CYCLE

      protected static final long MONIT_CYCLE
      Min. wait time between monitoring cycles.
      See Also:
    • LOSS_THRESHOLD

      protected static final long LOSS_THRESHOLD
      Threshold after which a _blocking_ thread is considered stolen.
      See Also:
    • LOSS_THRESHOLD_BUSY

      protected static final long LOSS_THRESHOLD_BUSY
      Threshold after which a _non-blocking_ thread is considered stolen.
      See Also:
    • idle

      protected AtomicInteger idle
      Number of idle threads in the pool.
    • threads

      protected volatile MonitoredThread[] threads
      The threads in the pool.
    • monitoringlock

      protected volatile Semaphore monitoringlock
      The lock for the monitoring thread.
    • monitthread

      protected Thread monitthread
      The monitoring thread.
    • monitoring

      protected boolean monitoring
      Flag for monitoring thread activity.
  • Constructor Details

    • MonitoredThreadPoolExecutor

      public MonitoredThreadPoolExecutor()
  • Method Details

    • execute

      public void execute(Runnable command)
      Specified by:
      execute in interface Executor
      Overrides:
      execute in class ThreadPoolExecutor
    • borrow

      protected void borrow(MonitoredThread thread)
      Borrows the thread.
      Parameters:
      thread - Thre thread being borrowed.
    • borrowNoUnpark

      protected void borrowNoUnpark(MonitoredThread thread)
      Borrows the thread without unparking.
      Parameters:
      thread - Thre thread being borrowed.
    • releaseLock

      protected static final void releaseLock(Semaphore lock)
      Releases the semaphore, includes null check.
      Parameters:
      lock - The lock.
    • currentThread

      protected static final MonitoredThread currentThread()
      Gets the current MonitoredThread, for convenience.
      Returns:
      Current MonitoredThread.