Package jadex.concurrent
Class MonitoredThreadPoolExecutor
java.lang.Object
java.util.concurrent.AbstractExecutorService
java.util.concurrent.ThreadPoolExecutor
jadex.concurrent.MonitoredThreadPoolExecutor
- All Implemented Interfaces:
AutoCloseable
,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 boolean
If true, be more aggressive when creating threads.protected static final int
Starting number of threads.protected static final boolean
Print debug messagesprotected AtomicInteger
Number of idle threads in the pool.protected static final long
Threshold after which a _blocking_ thread is considered stolen.protected static final long
Threshold after which a _non-blocking_ thread is considered stolen.protected static final long
Min.protected static final int
Threshold for activating monitoring.protected boolean
Flag for monitoring thread activity.protected Semaphore
The lock for the monitoring thread.protected Thread
The monitoring thread.protected MonitoredThread[]
The threads in the pool. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
borrow
(MonitoredThread thread) Borrows the thread.protected void
borrowNoUnpark
(MonitoredThread thread) Borrows the thread without unparking.protected static final MonitoredThread
Gets the current MonitoredThread, for convenience.void
protected static final void
releaseLock
(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
Methods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submit
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.concurrent.ExecutorService
close
-
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:
execute
in interfaceExecutor
- Overrides:
execute
in 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.
-