Package com.logicaldoc.core.threading

# Class ThreadPools

java.lang.Object
com.logicaldoc.core.threading.ThreadPools

@Component("threadPools") public class ThreadPools extends Object
A factory for thread pools. Each pool has a name and the details are taken from the configuration in the following as follows:

- threadpool.pool_name.core: the number of threads to keep in the pool, even if they are idle (defalut value: 5)
- threadpool.pool_name.max: the maximum number of threads to allow in the pool (defalut value: 10)
- threadpool.pool_name.keepalive: this is the maximum time(in seconds) that excess idle threads will wait for new tasks before terminating (defalut value: 5)
- threadpool.pool_name.type: this is the type default or scheduled(default value: default), default means

Since:
  8.5.3
Author:
  Marco Meschieri - LogicalDOC

## Constructor Summary

Constructors
Constructor
Description
`ThreadPools()`

## Method Summary

Modifier and Type
Method
Description
`<T> Future<T>`
`execute(Callable<T> task, String poolName)`
Executes a task in the given pool.
`static ThreadPools`
`get()`
Gets the object available in the application context
`ThreadPoolExecutor`
`getPool(String name)`
Gets a new thread pool and in case it does not exist a new one will be created and then cached.
`boolean`
`isRunning(String taskName)`
Gets the running status of a task
`void`
`kill(String taskName)`
Kills a task
`<T> Future<T>`
`schedule(Callable<T> task, String poolName, long delay)`
Schedule the execution of a task in a thread pool.
`void`
`shutdown()`
Shuts down all the pools

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### ThreadPools

public ThreadPools()

## Method Details

### get

public static ThreadPools get()
Gets the object available in the application context

Returns:
  the instance of this object in the application context

### getPool

public ThreadPoolExecutor getPool(String name) throws ThreadPoolNotAvailableException
Gets a new thread pool and in case it does not exist a new one will be created and then cached.

Parameters:
  `name` - the name of the new pool
Returns:
  the created pool
Throws:
  `ThreadPoolNotAvailableException` - Raised in case the pool has been shutdown

### schedule

public <T> Future<T> schedule(Callable<T> task, String poolName, long delay)
Schedule the execution of a task in a thread pool.

Parameters:
  `task` - The task to execute
  `poolName` - The name of the pool
  `delay` - a delay expressed in milliseconds

### execute

public <T> Future<T> execute(Callable<T> task, String poolName)
Executes a task in the given pool.

Parameters:
  `task` - The task to execute
  `poolName` - The name of the pool

### kill

public void kill(String taskName)
Kills a task

Parameters:
  `taskName` - Name of the thread

### isRunning

public boolean isRunning(String taskName)
Gets the running status of a task

Parameters:
  `taskName` - Name of the thread
Returns:
  If it is running

### shutdown

@PreDestroy public void shutdown()
Shuts down all the pools