public class SimpleThreadPool extends Object implements IThreadPool
This is class is a simple implementation of a thread pool, based on the
interface.
IThreadPool
Runnable objects are sent to the pool with the
method, which blocks until a
runInThread(Runnable)Thread becomes available.
The pool has a fixed number of Threads, and does not grow or
shrink based on demand.
| Constructor and Description |
|---|
SimpleThreadPool()
Create a new (unconfigured)
SimpleThreadPool. |
SimpleThreadPool(int threadCount,
int threadPriority)
Create a new
SimpleThreadPool with the specified number of
Thread s that have the given priority. |
| Modifier and Type | Method and Description |
|---|---|
int |
blockForAvailableThreads()
Determines the number of threads that are currently available in in the
pool.
|
protected void |
clearFromBusyWorkersList(com.helger.quartz.simpl.SimpleThreadPool.WorkerThread wt) |
protected List<com.helger.quartz.simpl.SimpleThreadPool.WorkerThread> |
createWorkerThreads(int createCount) |
int |
getPoolSize()
Get the current number of threads in the
ThreadPool. |
int |
getThreadCount()
Get the number of worker threads in the pool.
|
String |
getThreadNamePrefix() |
int |
getThreadPriority()
Get the thread priority of worker threads in the pool.
|
void |
initialize()
Must be called before the
ThreadPool is used, in order to give
the it a chance to initialize. |
boolean |
isMakeThreadsDaemons() |
boolean |
isThreadsInheritContextClassLoaderOfInitializingThread() |
boolean |
isThreadsInheritGroupOfInitializingThread() |
protected void |
makeAvailable(com.helger.quartz.simpl.SimpleThreadPool.WorkerThread wt) |
boolean |
runInThread(Runnable aRunnable)
Run the given
Runnable object in the next available
Thread. |
void |
setInstanceId(String schedInstId)
Inform the
ThreadPool of the Scheduler instance's Id, prior to
initialize being invoked. |
void |
setInstanceName(String schedName)
Inform the
ThreadPool of the Scheduler instance's name, prior
to initialize being invoked. |
void |
setMakeThreadsDaemons(boolean makeThreadsDaemons) |
void |
setThreadCount(int count)
Set the number of worker threads in the pool - has no effect after
initialize() has been called. |
void |
setThreadNamePrefix(String prfx) |
void |
setThreadPriority(int prio)
Set the thread priority of worker threads in the pool - has no effect after
initialize() has been called. |
void |
setThreadsInheritContextClassLoaderOfInitializingThread(boolean inheritLoader) |
void |
setThreadsInheritGroupOfInitializingThread(boolean inheritGroup) |
void |
shutdown()
Terminate any worker threads in this thread group.
|
void |
shutdown(boolean waitForJobsToComplete)
Terminate any worker threads in this thread group.
|
public SimpleThreadPool()
SimpleThreadPool.setThreadCount(int),
setThreadPriority(int)public SimpleThreadPool(int threadCount,
int threadPriority)
Create a new SimpleThreadPool with the specified number of
Thread s that have the given priority.
threadCount - the number of worker Threads in the pool, must be >
0.threadPriority - the thread priority for the worker threads.Threadpublic int getPoolSize()
IThreadPool
Get the current number of threads in the ThreadPool.
getPoolSize in interface IThreadPoolpublic final void setThreadCount(int count)
Set the number of worker threads in the pool - has no effect after
initialize() has been called.
public final int getThreadCount()
Get the number of worker threads in the pool.
public final void setThreadPriority(int prio)
Set the thread priority of worker threads in the pool - has no effect after
initialize() has been called.
public final int getThreadPriority()
Get the thread priority of worker threads in the pool.
public final boolean isThreadsInheritContextClassLoaderOfInitializingThread()
public final void setThreadsInheritContextClassLoaderOfInitializingThread(boolean inheritLoader)
inheritLoader - The threadsInheritContextClassLoaderOfInitializingThread to set.public final boolean isThreadsInheritGroupOfInitializingThread()
public final void setThreadsInheritGroupOfInitializingThread(boolean inheritGroup)
public final boolean isMakeThreadsDaemons()
public final void setMakeThreadsDaemons(boolean makeThreadsDaemons)
makeThreadsDaemons - The value of makeThreadsDaemons to set.public void setInstanceId(String schedInstId)
IThreadPool
Inform the ThreadPool of the Scheduler instance's Id, prior to
initialize being invoked.
setInstanceId in interface IThreadPoolpublic void setInstanceName(String schedName)
IThreadPool
Inform the ThreadPool of the Scheduler instance's name, prior
to initialize being invoked.
setInstanceName in interface IThreadPoolpublic void initialize()
throws SchedulerConfigException
IThreadPool
Must be called before the ThreadPool is used, in order to give
the it a chance to initialize.
Typically called by the SchedulerFactory.
initialize in interface IThreadPoolSchedulerConfigExceptionprotected List<com.helger.quartz.simpl.SimpleThreadPool.WorkerThread> createWorkerThreads(int createCount)
public void shutdown()
Terminate any worker threads in this thread group.
Jobs currently in progress will complete.
public void shutdown(boolean waitForJobsToComplete)
Terminate any worker threads in this thread group.
Jobs currently in progress will complete.
shutdown in interface IThreadPoolpublic boolean runInThread(Runnable aRunnable)
Run the given Runnable object in the next available
Thread. If while waiting the thread pool is asked to shut
down, the Runnable is executed immediately within a new additional thread.
runInThread in interface IThreadPoolaRunnable - the Runnable to be added.public int blockForAvailableThreads()
IThreadPool
Determines the number of threads that are currently available in in the
pool. Useful for determining the number of times
runInThread(Runnable) can be called before returning false.
The implementation of this method should block until there is at least one available thread.
blockForAvailableThreads in interface IThreadPoolprotected void makeAvailable(com.helger.quartz.simpl.SimpleThreadPool.WorkerThread wt)
protected void clearFromBusyWorkersList(com.helger.quartz.simpl.SimpleThreadPool.WorkerThread wt)
Copyright © 2016–2021 Philip Helger. All rights reserved.