Package org.openhab.core.common
Class ThreadPoolManager
java.lang.Object
org.openhab.core.common.ThreadPoolManager
This class provides a general mechanism to create thread pools. In general, no code of openHAB should deal with its own pools, but rather use this class. The created thread pools have named threads, so that it is easy to find them in the debugger. Additionally, it is possible to configure the pool sizes through the configuration admin service, so that solutions have the chance to tweak the pool sizes according to their needs.
The configuration can be done as
org.openhab.core.threadpool:<poolName>=<poolSize>
All threads will time out after THREAD_TIMEOUT
.
- Author:
- Kai Kreuzer - Initial contribution
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
protected static final int
protected static Map<String,
ExecutorService> protected static final long
static final String
The common thread pool is reserved for occasional, light weight tasks that run quickly, and use little resources to execute.protected static final long
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
protected static int
static ExecutorService
Returns an instance of a cached thread pool service.static ScheduledExecutorService
getPoolBasedSequentialScheduledExecutorService
(String poolName, String threadName) Returns an instance of a scheduled service, which will sequentially execute submitted tasks.static ScheduledExecutorService
getScheduledPool
(String poolName) Returns an instance of a scheduled thread pool service.protected void
-
Field Details
-
CONFIGURATION_PID
- See Also:
-
THREAD_POOL_NAME_COMMON
The common thread pool is reserved for occasional, light weight tasks that run quickly, and use little resources to execute. Tasks that do not fit into this category should setup their own dedicated pool or permanent thread.- See Also:
-
DEFAULT_THREAD_POOL_SIZE
protected static final int DEFAULT_THREAD_POOL_SIZE- See Also:
-
THREAD_TIMEOUT
protected static final long THREAD_TIMEOUT- See Also:
-
THREAD_MONITOR_SLEEP
protected static final long THREAD_MONITOR_SLEEP- See Also:
-
pools
-
-
Constructor Details
-
ThreadPoolManager
public ThreadPoolManager()
-
-
Method Details
-
activate
-
modified
-
getPoolBasedSequentialScheduledExecutorService
public static ScheduledExecutorService getPoolBasedSequentialScheduledExecutorService(String poolName, String threadName) Returns an instance of a scheduled service, which will sequentially execute submitted tasks. If a task is currently running the task is queued until the previous one is completed, this also applies for scheduled tasks. The service might execute submitted task might in different threads, but still one after the other. If it is the first request for the given pool name and a pool is used, the instance is newly created.- Parameters:
poolName
- a short name used to identify the pool, if a thread pool is used e.g. "bluetooth-discovery"threadName
- a short name used to identify the thread if no thread pool is used, e.g. "bluetooth"- Returns:
- an instance to use
-
getScheduledPool
Returns an instance of a scheduled thread pool service. If it is the first request for the given pool name, the instance is newly created.- Parameters:
poolName
- a short name used to identify the pool, e.g. "discovery"- Returns:
- an instance to use
-
getPool
Returns an instance of a cached thread pool service. If it is the first request for the given pool name, the instance is newly created.- Parameters:
poolName
- a short name used to identify the pool, e.g. "discovery"- Returns:
- an instance to use
-
getConfig
-
getPoolNames
-