Class ThreadPoolManager

java.lang.Object
org.openhab.core.common.ThreadPoolManager

public class ThreadPoolManager extends Object

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 Details

    • CONFIGURATION_PID

      public static final String CONFIGURATION_PID
      See Also:
    • THREAD_POOL_NAME_COMMON

      public static final String 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

      protected static Map<String,ExecutorService> pools
  • Constructor Details

    • ThreadPoolManager

      public ThreadPoolManager()
  • Method Details

    • activate

      protected void activate(Map<String,Object> properties)
    • modified

      protected void modified(Map<String,Object> properties)
    • getScheduledPool

      public static ScheduledExecutorService getScheduledPool(String poolName)
      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

      public static ExecutorService getPool(String poolName)
      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

      protected static int getConfig(String poolName)
    • getPoolNames

      public static Set<String> getPoolNames()