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.ThreadPool
Runnable
objects are sent to the pool with the
method, which blocks until arunInThread(Runnable)
Thread
becomes available.The pool has a fixed number of
Thread
s, 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 newSimpleThreadPool
with the specified number ofThread
s that have the given priority.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
blockForAvailableThreads()
Determines the number of threads that are currently available in in the pool.protected void
clearFromBusyWorkersList(org.quartz.simpl.SimpleThreadPool.WorkerThread wt)
protected java.util.List<org.quartz.simpl.SimpleThreadPool.WorkerThread>
createWorkerThreads(int createCount)
org.slf4j.Logger
getLog()
int
getPoolSize()
Get the current number of threads in theThreadPool
.int
getThreadCount()
Get the number of worker threads in the pool.java.lang.String
getThreadNamePrefix()
int
getThreadPriority()
Get the thread priority of worker threads in the pool.void
initialize()
Must be called before theThreadPool
is used, in order to give the it a chance to initialize.boolean
isMakeThreadsDaemons()
boolean
isThreadsInheritContextClassLoaderOfInitializingThread()
boolean
isThreadsInheritGroupOfInitializingThread()
protected void
makeAvailable(org.quartz.simpl.SimpleThreadPool.WorkerThread wt)
boolean
runInThread(java.lang.Runnable runnable)
Run the givenRunnable
object in the next availableThread
.void
setInstanceId(java.lang.String schedInstId)
Inform theThreadPool
of the Scheduler instance's Id, prior to initialize being invoked.void
setInstanceName(java.lang.String schedName)
Inform theThreadPool
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 afterinitialize()
has been called.void
setThreadNamePrefix(java.lang.String prfx)
void
setThreadPriority(int prio)
Set the thread priority of worker threads in the pool - has no effect afterinitialize()
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.
-
-
-
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
SimpleThreadPool
with the specified number ofThread
s that have the given priority.- Parameters:
threadCount
- the number of workerThreads
in 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:ThreadPool
Get the current number of threads in the
ThreadPool
.- Specified by:
getPoolSize
in 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 prfx)
-
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:ThreadPool
Inform the
ThreadPool
of the Scheduler instance's Id, prior to initialize being invoked.- Specified by:
setInstanceId
in interfaceThreadPool
-
setInstanceName
public void setInstanceName(java.lang.String schedName)
Description copied from interface:ThreadPool
Inform the
ThreadPool
of the Scheduler instance's name, prior to initialize being invoked.- Specified by:
setInstanceName
in interfaceThreadPool
-
initialize
public void initialize() throws SchedulerConfigException
Description copied from interface:ThreadPool
Must be called before the
ThreadPool
is used, in order to give the it a chance to initialize.Typically called by the
SchedulerFactory
.- Specified by:
initialize
in 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:
shutdown
in interfaceThreadPool
-
runInThread
public boolean runInThread(java.lang.Runnable runnable)
Run the given
Runnable
object 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:
runInThread
in interfaceThreadPool
- Parameters:
runnable
- theRunnable
to be added.- Returns:
- true, if the runnable was assigned to run on a Thread.
-
blockForAvailableThreads
public int blockForAvailableThreads()
Description copied from interface:ThreadPool
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.
- Specified by:
blockForAvailableThreads
in 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)
-
-