Package jadex.commons.concurrent
Class MonitoredThreadPoolExecutor
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- java.util.concurrent.ThreadPoolExecutor
-
- jadex.commons.concurrent.MonitoredThreadPoolExecutor
-
- All Implemented Interfaces:
java.util.concurrent.Executor
,java.util.concurrent.ExecutorService
public class MonitoredThreadPoolExecutor extends java.util.concurrent.ThreadPoolExecutor
Thread pool executor based on the Java 5 ThreadPoolExecutor class. Uses a monitoring thread to monitor pool thread behavior to adjust pool size.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.concurrent.ThreadPoolExecutor
java.util.concurrent.ThreadPoolExecutor.AbortPolicy, java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy, java.util.concurrent.ThreadPoolExecutor.DiscardOldestPolicy, java.util.concurrent.ThreadPoolExecutor.DiscardPolicy
-
-
Field Summary
Fields Modifier and Type Field Description protected static boolean
AGGRESSIVE
If true, be more aggressive when creating threads.protected static int
BASE_TCNT
Starting number of threads.protected static boolean
DEBUG
Print debug messagesprotected java.util.concurrent.atomic.AtomicInteger
idle
Number of idle threads in the pool.protected static long
LOSS_THRESHOLD
Threshold after which a _blocking_ thread is considered stolen.protected static long
LOSS_THRESHOLD_BUSY
Threshold after which a _non-blocking_ thread is considered stolen.protected static long
MONIT_CYCLE
Min.protected static int
MONIT_THRESHOLD
Threshold for activating monitoring.protected boolean
monitoring
Flag for monitoring thread activity.protected java.util.concurrent.Semaphore
monitoringlock
The lock for the monitoring thread.protected java.lang.Thread
monitthread
The monitoring thread.protected MonitoredThread[]
threads
The threads in the pool.
-
Constructor Summary
Constructors Constructor Description MonitoredThreadPoolExecutor()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
borrow(MonitoredThread thread)
Borrows the thread.protected void
borrowNoUnpark(MonitoredThread thread)
Borrows the thread without unparking.protected static MonitoredThread
currentThread()
Gets the current MonitoredThread, for convenience.void
execute(java.lang.Runnable command)
protected static void
releaseLock(java.util.concurrent.Semaphore lock)
Releases the semaphore, includes null check.-
Methods inherited from class java.util.concurrent.ThreadPoolExecutor
afterExecute, allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, beforeExecute, finalize, getActiveCount, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getQueue, getRejectedExecutionHandler, getTaskCount, getThreadFactory, isShutdown, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setCorePoolSize, setKeepAliveTime, setMaximumPoolSize, setRejectedExecutionHandler, setThreadFactory, shutdown, shutdownNow, terminated, toString
-
-
-
-
Field Detail
-
DEBUG
protected static final boolean DEBUG
Print debug messages- See Also:
- Constant Field Values
-
AGGRESSIVE
protected static final boolean AGGRESSIVE
If true, be more aggressive when creating threads.- See Also:
- Constant Field Values
-
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:
- Constant Field Values
-
LOSS_THRESHOLD
protected static final long LOSS_THRESHOLD
Threshold after which a _blocking_ thread is considered stolen.- See Also:
- Constant Field Values
-
LOSS_THRESHOLD_BUSY
protected static final long LOSS_THRESHOLD_BUSY
Threshold after which a _non-blocking_ thread is considered stolen.- See Also:
- Constant Field Values
-
idle
protected java.util.concurrent.atomic.AtomicInteger idle
Number of idle threads in the pool.
-
threads
protected volatile MonitoredThread[] threads
The threads in the pool.
-
monitoringlock
protected volatile java.util.concurrent.Semaphore monitoringlock
The lock for the monitoring thread.
-
monitthread
protected java.lang.Thread monitthread
The monitoring thread.
-
monitoring
protected boolean monitoring
Flag for monitoring thread activity.
-
-
Method Detail
-
execute
public void execute(java.lang.Runnable command)
- Specified by:
execute
in interfacejava.util.concurrent.Executor
- Overrides:
execute
in classjava.util.concurrent.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(java.util.concurrent.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.
-
-