Package com.logicaldoc.core.threading
Class ThreadPools
- java.lang.Object
-
- com.logicaldoc.core.threading.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)
- Since:
- 8.5.3
- Author:
- Marco Meschieri - LogicalDOC
-
-
Constructor Summary
Constructors Constructor Description ThreadPools()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
execute(Runnable task, String poolName)
Executes a task in the given pool.static ThreadPools
get()
ExecutorService
getPool(String name)
Gets a new thread pool and in case it does not exist a new one will be created and then cached.void
schedule(Runnable task, String poolName, long delay)
Schedule the execution of a task in a thread pool.void
setConfig(ContextProperties config)
void
shutdown()
Shuts down all the poolsvoid
start()
-
-
-
Method Detail
-
setConfig
public void setConfig(ContextProperties config)
-
get
public static ThreadPools get()
-
start
public void start()
-
getPool
public ExecutorService getPool(String name)
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
-
schedule
public void schedule(Runnable task, String poolName, long delay)
Schedule the execution of a task in a thread pool.- Parameters:
task
- The task to executepoolName
- The name of the pooldelay
- a delay expressed in milliseconds
-
execute
public void execute(Runnable task, String poolName)
Executes a task in the given pool.- Parameters:
task
- The task to executepoolName
- The name of the pool
-
shutdown
public void shutdown()
Shuts down all the pools
-
-