@ThreadSafe public class ThreadPools extends Object implements ThreadPoolFactory
ThreadPoolFactory
implementation.Constructor and Description |
---|
ThreadPools() |
Modifier and Type | Method and Description |
---|---|
ExecutorService |
getCachedTreadPool(String name,
int maxPoolSize)
Signal that the supplied thread pool is no longer needed.
|
ScheduledExecutorService |
getScheduledThreadPool(String name)
Obtain a scheduled thread pool with the supplied name, or create and return one if no thread pool exists with that name.
|
ExecutorService |
getThreadPool(String name)
Obtain a thread pool with the supplied name, or create and return one if no thread pool exists with that name.
|
void |
releaseThreadPool(ExecutorService executor)
Performs a
ExecutorService.shutdownNow() on the given pool, if the pool has been created
previously by this class. |
void |
terminateAllPools(long maxWaitTime,
TimeUnit unit)
Terminates all the existing thread pool, by waiting for them maximum
maxWaitTimeMillis milliseconds, after which
calling ExecutorService.shutdownNow() . |
public ExecutorService getThreadPool(String name)
ThreadPoolFactory
released
.getThreadPool
in interface ThreadPoolFactory
name
- the name of the thread pool; may not be nullpublic ExecutorService getCachedTreadPool(String name, int maxPoolSize)
ThreadPoolFactory
released
.getCachedTreadPool
in interface ThreadPoolFactory
name
- the name of the thread pool; may not be nullmaxPoolSize
- the maximum number of threads that can be spawned by this pool.public ScheduledExecutorService getScheduledThreadPool(String name)
ThreadPoolFactory
released
.getScheduledThreadPool
in interface ThreadPoolFactory
name
- the name of the thread pool; may not be nullpublic void releaseThreadPool(ExecutorService executor)
ThreadPoolFactory
ExecutorService.shutdownNow()
on the given pool, if the pool has been created
previously by this class. Clients which use this method should handle, if necessary, any potential
InterruptedException
releaseThreadPool
in interface ThreadPoolFactory
executor
- the pool that is no longer neededpublic void terminateAllPools(long maxWaitTime, TimeUnit unit)
ThreadPoolFactory
maxWaitTimeMillis
milliseconds, after which
calling ExecutorService.shutdownNow()
.terminateAllPools
in interface ThreadPoolFactory
maxWaitTime
- the maximum amount of time that should be given to the pools to shutdown on their own; must be
non-negativeunit
- the unit of time for the maxWaitTime
parameterCopyright © 2008–2016 JBoss, a division of Red Hat. All rights reserved.