Package org.openhab.core.common
Class QueueingThreadPoolExecutor
java.lang.Object
java.util.concurrent.AbstractExecutorService
java.util.concurrent.ThreadPoolExecutor
org.openhab.core.common.QueueingThreadPoolExecutor
- All Implemented Interfaces:
AutoCloseable
,Executor
,ExecutorService
This is a thread pool executor service, which works as a developer would expect it to work.
The default
ThreadPoolExecutor
does the following (see
the
official JavaDoc):
- If fewer than corePoolSize threads are running, the Executor always prefers adding a new thread rather than queuing.
- If corePoolSize or more threads are running, the Executor always prefers queuing a request rather than adding a new thread.
- If a request cannot be queued, a new thread is created unless this would exceed maximumPoolSize, in which case, the task will be rejected.
- corePoolSize is 1, so threads are only created on demand
- If the number of busy threads is smaller than the threadPoolSize, the Executor always prefers adding (or reusing) a thread rather than queuing it.
- If threadPoolSize threads are busy, new requests will be put in a FIFO queue and processed as soon as a thread becomes idle.
- The queue size is unbound, i.e. requests will never be rejected.
- Threads are terminated after being idle for at least 10 seconds.
- Author:
- Kai Kreuzer - Initial contribution
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.concurrent.ThreadPoolExecutor
ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicy
-
Constructor Summary
ModifierConstructorDescriptionprotected
QueueingThreadPoolExecutor
(String name, int threadPoolSize) Allows to subclass QueueingThreadPoolExecutor. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addToQueue
(Runnable runnable) Adds a new task to the queueprotected void
afterExecute
(Runnable r, Throwable t) static QueueingThreadPoolExecutor
createInstance
(String name, int threadPoolSize) Creates a new instance ofQueueingThreadPoolExecutor
.void
getQueue()
void
This implementation does not allow setting a custom handler.Methods inherited from class java.util.concurrent.ThreadPoolExecutor
allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, beforeExecute, finalize, getActiveCount, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getRejectedExecutionHandler, getTaskCount, getThreadFactory, isShutdown, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setCorePoolSize, setKeepAliveTime, setMaximumPoolSize, 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
-
Constructor Details
-
QueueingThreadPoolExecutor
Allows to subclass QueueingThreadPoolExecutor.
-
-
Method Details
-
createInstance
Creates a new instance ofQueueingThreadPoolExecutor
.- Parameters:
name
- the name of the thread pool, will be used as a prefix for the name of the threadsthreadPoolSize
- the maximum size of the pool- Returns:
- the
QueueingThreadPoolExecutor
instance
-
addToQueue
Adds a new task to the queue- Parameters:
runnable
- the task to add
-
afterExecute
- Overrides:
afterExecute
in classThreadPoolExecutor
-
setRejectedExecutionHandler
This implementation does not allow setting a custom handler.- Overrides:
setRejectedExecutionHandler
in classThreadPoolExecutor
- Throws:
UnsupportedOperationException
- if called.
-
getQueue
- Overrides:
getQueue
in classThreadPoolExecutor
-
execute
- Specified by:
execute
in interfaceExecutor
- Overrides:
execute
in classThreadPoolExecutor
-