Package jadex.concurrent
Class MonitoredThreadPoolExecutor
java.lang.Object
java.util.concurrent.AbstractExecutorService
java.util.concurrent.ThreadPoolExecutor
jadex.concurrent.MonitoredThreadPoolExecutor
- All Implemented Interfaces:
Executor,ExecutorService
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
ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicy -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final booleanIf true, be more aggressive when creating threads.protected static final intStarting number of threads.protected static final booleanPrint debug messagesprotected AtomicIntegerNumber of idle threads in the pool.protected static final longThreshold after which a _blocking_ thread is considered stolen.protected static final longThreshold after which a _non-blocking_ thread is considered stolen.protected static final longMin.protected static final intThreshold for activating monitoring.protected booleanFlag for monitoring thread activity.protected SemaphoreThe lock for the monitoring thread.protected ThreadThe monitoring thread.protected MonitoredThread[]The threads in the pool. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidborrow(MonitoredThread thread) Borrows the thread.protected voidborrowNoUnpark(MonitoredThread thread) Borrows the thread without unparking.protected static final MonitoredThreadGets the current MonitoredThread, for convenience.voidprotected static final voidreleaseLock(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, toStringMethods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submit
-
Field Details
-
DEBUG
protected static final boolean DEBUGPrint debug messages- See Also:
-
AGGRESSIVE
protected static final boolean AGGRESSIVEIf true, be more aggressive when creating threads.- See Also:
-
MONIT_THRESHOLD
protected static final int MONIT_THRESHOLDThreshold for activating monitoring. -
BASE_TCNT
protected static final int BASE_TCNTStarting number of threads. -
MONIT_CYCLE
protected static final long MONIT_CYCLEMin. wait time between monitoring cycles.- See Also:
-
LOSS_THRESHOLD
protected static final long LOSS_THRESHOLDThreshold after which a _blocking_ thread is considered stolen.- See Also:
-
LOSS_THRESHOLD_BUSY
protected static final long LOSS_THRESHOLD_BUSYThreshold after which a _non-blocking_ thread is considered stolen.- See Also:
-
idle
Number of idle threads in the pool. -
threads
The threads in the pool. -
monitoringlock
The lock for the monitoring thread. -
monitthread
The monitoring thread. -
monitoring
protected boolean monitoringFlag for monitoring thread activity.
-
-
Constructor Details
-
MonitoredThreadPoolExecutor
public MonitoredThreadPoolExecutor()
-
-
Method Details
-
execute
- Specified by:
executein interfaceExecutor- Overrides:
executein classThreadPoolExecutor
-
borrow
Borrows the thread.- Parameters:
thread- Thre thread being borrowed.
-
borrowNoUnpark
Borrows the thread without unparking.- Parameters:
thread- Thre thread being borrowed.
-
releaseLock
Releases the semaphore, includes null check.- Parameters:
lock- The lock.
-
currentThread
Gets the current MonitoredThread, for convenience.- Returns:
- Current MonitoredThread.
-