Class SimpleThreadPool
- java.lang.Object
-
- org.quartz.simpl.SimpleThreadPool
-
- All Implemented Interfaces:
ThreadPool
public class SimpleThreadPool extends java.lang.Object implements ThreadPool
This is class is a simple implementation of a thread pool, based on the
interface.ThreadPoolRunnableobjects are sent to the pool with themethod, which blocks until arunInThread(Runnable)Threadbecomes available.The pool has a fixed number of
Threads, and does not grow or shrink based on demand.- Author:
- James House, Juergen Donnerstag
-
-
Constructor Summary
Constructors Constructor Description SimpleThreadPool()Create a new (unconfigured)SimpleThreadPool.SimpleThreadPool(int threadCount, int threadPriority)Create a newSimpleThreadPoolwith the specified number ofThreads that have the given priority.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intblockForAvailableThreads()Determines the number of threads that are currently available in in the pool.protected voidclearFromBusyWorkersList(org.quartz.simpl.SimpleThreadPool.WorkerThread wt)protected java.util.List<org.quartz.simpl.SimpleThreadPool.WorkerThread>createWorkerThreads(int createCount)org.slf4j.LoggergetLog()intgetPoolSize()Get the current number of threads in theThreadPool.intgetThreadCount()Get the number of worker threads in the pool.java.lang.StringgetThreadNamePrefix()intgetThreadPriority()Get the thread priority of worker threads in the pool.voidinitialize()Must be called before theThreadPoolis used, in order to give the it a chance to initialize.booleanisMakeThreadsDaemons()booleanisThreadsInheritContextClassLoaderOfInitializingThread()booleanisThreadsInheritGroupOfInitializingThread()protected voidmakeAvailable(org.quartz.simpl.SimpleThreadPool.WorkerThread wt)booleanrunInThread(java.lang.Runnable runnable)Run the givenRunnableobject in the next availableThread.voidsetInstanceId(java.lang.String schedInstId)Inform theThreadPoolof the Scheduler instance's Id, prior to initialize being invoked.voidsetInstanceName(java.lang.String schedName)Inform theThreadPoolof the Scheduler instance's name, prior to initialize being invoked.voidsetMakeThreadsDaemons(boolean makeThreadsDaemons)voidsetThreadCount(int count)Set the number of worker threads in the pool - has no effect afterinitialize()has been called.voidsetThreadNamePrefix(java.lang.String prefix)voidsetThreadPriority(int prio)Set the thread priority of worker threads in the pool - has no effect afterinitialize()has been called.voidsetThreadsInheritContextClassLoaderOfInitializingThread(boolean inheritLoader)voidsetThreadsInheritGroupOfInitializingThread(boolean inheritGroup)voidshutdown()Terminate any worker threads in this thread group.voidshutdown(boolean waitForJobsToComplete)Terminate any worker threads in this thread group.
-
-
-
Constructor Detail
-
SimpleThreadPool
public SimpleThreadPool()
Create a new (unconfigured)
SimpleThreadPool.- See Also:
setThreadCount(int),setThreadPriority(int)
-
SimpleThreadPool
public SimpleThreadPool(int threadCount, int threadPriority)Create a new
SimpleThreadPoolwith the specified number ofThreads that have the given priority.- Parameters:
threadCount- the number of workerThreadsin the pool, must be > 0.threadPriority- the thread priority for the worker threads.- See Also:
Thread
-
-
Method Detail
-
getLog
public org.slf4j.Logger getLog()
-
getPoolSize
public int getPoolSize()
Description copied from interface:ThreadPoolGet the current number of threads in the
ThreadPool.- Specified by:
getPoolSizein interfaceThreadPool
-
setThreadCount
public void setThreadCount(int count)
Set the number of worker threads in the pool - has no effect after
initialize()has been called.
-
getThreadCount
public int getThreadCount()
Get the number of worker threads in the pool.
-
setThreadPriority
public void setThreadPriority(int prio)
Set the thread priority of worker threads in the pool - has no effect after
initialize()has been called.
-
getThreadPriority
public int getThreadPriority()
Get the thread priority of worker threads in the pool.
-
setThreadNamePrefix
public void setThreadNamePrefix(java.lang.String prefix)
-
getThreadNamePrefix
public java.lang.String getThreadNamePrefix()
-
isThreadsInheritContextClassLoaderOfInitializingThread
public boolean isThreadsInheritContextClassLoaderOfInitializingThread()
- Returns:
- Returns the threadsInheritContextClassLoaderOfInitializingThread.
-
setThreadsInheritContextClassLoaderOfInitializingThread
public void setThreadsInheritContextClassLoaderOfInitializingThread(boolean inheritLoader)
- Parameters:
inheritLoader- The threadsInheritContextClassLoaderOfInitializingThread to set.
-
isThreadsInheritGroupOfInitializingThread
public boolean isThreadsInheritGroupOfInitializingThread()
-
setThreadsInheritGroupOfInitializingThread
public void setThreadsInheritGroupOfInitializingThread(boolean inheritGroup)
-
isMakeThreadsDaemons
public boolean isMakeThreadsDaemons()
- Returns:
- Returns the value of makeThreadsDaemons.
-
setMakeThreadsDaemons
public void setMakeThreadsDaemons(boolean makeThreadsDaemons)
- Parameters:
makeThreadsDaemons- The value of makeThreadsDaemons to set.
-
setInstanceId
public void setInstanceId(java.lang.String schedInstId)
Description copied from interface:ThreadPoolInform the
ThreadPoolof the Scheduler instance's Id, prior to initialize being invoked.- Specified by:
setInstanceIdin interfaceThreadPool
-
setInstanceName
public void setInstanceName(java.lang.String schedName)
Description copied from interface:ThreadPoolInform the
ThreadPoolof the Scheduler instance's name, prior to initialize being invoked.- Specified by:
setInstanceNamein interfaceThreadPool
-
initialize
public void initialize() throws SchedulerConfigExceptionDescription copied from interface:ThreadPoolMust be called before the
ThreadPoolis used, in order to give the it a chance to initialize.Typically called by the
SchedulerFactory.- Specified by:
initializein interfaceThreadPool- Throws:
SchedulerConfigException
-
createWorkerThreads
protected java.util.List<org.quartz.simpl.SimpleThreadPool.WorkerThread> createWorkerThreads(int createCount)
-
shutdown
public void shutdown()
Terminate any worker threads in this thread group.
Jobs currently in progress will complete.
-
shutdown
public void shutdown(boolean waitForJobsToComplete)
Terminate any worker threads in this thread group.
Jobs currently in progress will complete.
- Specified by:
shutdownin interfaceThreadPool
-
runInThread
public boolean runInThread(java.lang.Runnable runnable)
Run the given
Runnableobject in the next availableThread. If while waiting the thread pool is asked to shut down, the Runnable is executed immediately within a new additional thread.- Specified by:
runInThreadin interfaceThreadPool- Parameters:
runnable- theRunnableto be added.- Returns:
- true, if the runnable was assigned to run on a Thread.
-
blockForAvailableThreads
public int blockForAvailableThreads()
Description copied from interface:ThreadPoolDetermines 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.
- Specified by:
blockForAvailableThreadsin interfaceThreadPool- Returns:
- the number of currently available threads
-
makeAvailable
protected void makeAvailable(org.quartz.simpl.SimpleThreadPool.WorkerThread wt)
-
clearFromBusyWorkersList
protected void clearFromBusyWorkersList(org.quartz.simpl.SimpleThreadPool.WorkerThread wt)
-
-