Package org.jppf.utils.concurrent
Class JPPFThreadPool
java.lang.Object
java.util.concurrent.AbstractExecutorService
org.jppf.utils.concurrent.JPPFThreadPool
- All Implemented Interfaces:
Executor,ExecutorService
A thread pool based on an ubounded queue which supports a core and maximum number of threads, along with a TTL for non-core threads.
Core threads are always live and are always prefered when available for new tasks. Non-core threads are created up to the maximum number of threads, after which tasks are simpy put into the queue.
- Author:
- Laurent Cohen
-
Constructor Summary
ConstructorsConstructorDescriptionJPPFThreadPool(int coreThreads) Create a fixed size thread pool with the specified number of threads, infinite thread time-to-live and adefault thread factory.JPPFThreadPool(int coreThreads, int maxThreads, long ttl) Initialize with the specified number of core threads, maximum number of threads, thread ttl and adefault thread factory.JPPFThreadPool(int coreThreads, int maxThreads, long ttl, ThreadFactory threadFactory) Initialize with the specified number of core threads, maximum number of threads, ttl and thread factory.JPPFThreadPool(int coreThreads, int maxThreads, long ttl, ThreadFactory threadFactory, BlockingQueue<Runnable> queue) Initialize with the specified number of core threads, maximum number of threads, ttl and thread factory.JPPFThreadPool(int coreThreads, ThreadFactory threadFactory) Initialize with the specified number of core threads and thread factory. -
Method Summary
Modifier and TypeMethodDescriptionbooleanawaitTermination(long timeout, TimeUnit unit) voidExecute the specified task some time in the future.intintlonggetTtl()booleanbooleanvoidsetMaxThreads(int maxThreads) Set the maximum number of threads.voidsetTtl(long ttl) Set the non-core threads' time-to-live.voidshutdown()toString()Methods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submit
-
Constructor Details
-
JPPFThreadPool
public JPPFThreadPool(int coreThreads) Create a fixed size thread pool with the specified number of threads, infinite thread time-to-live and adefault thread factory.- Parameters:
coreThreads- the number of threads in the pool.
-
JPPFThreadPool
Initialize with the specified number of core threads and thread factory.- Parameters:
coreThreads- the number of core threads.threadFactory- the thread factory.
-
JPPFThreadPool
public JPPFThreadPool(int coreThreads, int maxThreads, long ttl) Initialize with the specified number of core threads, maximum number of threads, thread ttl and adefault thread factory.- Parameters:
coreThreads- the number of core threads.maxThreads- the maximum number of threads.ttl- the thread time-to-live in milliseconds.
-
JPPFThreadPool
Initialize with the specified number of core threads, maximum number of threads, ttl and thread factory.- Parameters:
coreThreads- the number of core threads.maxThreads- the maximum number of threads.ttl- the thread time-to-live in milliseconds.threadFactory- the thread factory.
-
JPPFThreadPool
public JPPFThreadPool(int coreThreads, int maxThreads, long ttl, ThreadFactory threadFactory, BlockingQueue<Runnable> queue) Initialize with the specified number of core threads, maximum number of threads, ttl and thread factory.- Parameters:
coreThreads- the number of core threads.maxThreads- the maximum number of threads.ttl- the thread time-to-live in milliseconds.threadFactory- the thread factory.queue- the queue to use.
-
-
Method Details
-
getMaxThreads
public int getMaxThreads()- Returns:
- the maximum number of threads.
-
setMaxThreads
public void setMaxThreads(int maxThreads) Set the maximum number of threads.- Parameters:
maxThreads- the new maximum number of threads.
-
getTtl
public long getTtl()- Returns:
- the non-threads' time-to-live.
-
setTtl
public void setTtl(long ttl) Set the non-core threads' time-to-live.- Parameters:
ttl- the ttl in millis.
-
getPeakThreadCount
public int getPeakThreadCount()- Returns:
- the peak thread count for this thread pool.
-
execute
Execute the specified task some time in the future.- Parameters:
task- the task to execute.
-
shutdown
public void shutdown() -
shutdownNow
-
isShutdown
public boolean isShutdown() -
isTerminated
public boolean isTerminated() -
awaitTermination
- Throws:
InterruptedException
-
toString
-