Package org.quartz.core
Class SimpleThreadPool
java.lang.Object
org.quartz.core.SimpleThreadPool
- All Implemented Interfaces:
ThreadPool
This is class is a simple implementation of a thread pool, based on the
ThreadPool interface.
Runnable objects are sent to the pool with the
method, which blocks until a runInThread(JobRunShell)Thread becomes
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 -
Method Summary
Modifier and TypeMethodDescriptionintDetermines the number of threads that are currently available in in the pool.intGet the current number of threads in theThreadPool.intGet the number of worker threads in the pool.intGet the thread priority of worker threads in the pool.voidMust be called before theThreadPoolis used, in order to give the it a chance to initialize.booleanbooleanbooleanbooleanrunInThread(JobRunShell runnable) Run the givenRunnableobject in the next availableThread.voidsetInstanceId(String schedInstId) voidsetMakeThreadsDaemons(boolean makeThreadsDaemons) voidsetThreadCount(int count) Set the number of worker threads in the pool - has no effect afterinitialize()has been called.voidsetThreadNamePrefix(String prfx) 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.
-
Constructor Details
-
SimpleThreadPool
public SimpleThreadPool()Create a new (unconfigured)SimpleThreadPool.- See Also:
-
-
Method Details
-
getPoolSize
public int getPoolSize()Description copied from interface:ThreadPoolGet the current number of threads in theThreadPool.- Specified by:
getPoolSizein interfaceThreadPool
-
setThreadCount
public void setThreadCount(int count) Set the number of worker threads in the pool - has no effect afterinitialize()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 afterinitialize()has been called. -
getThreadPriority
public int getThreadPriority()Get the thread priority of worker threads in the pool. -
setThreadNamePrefix
-
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
-
initialize
Description copied from interface:ThreadPoolMust be called before theThreadPoolis used, in order to give the it a chance to initialize.Typically called by the
SchedulerFactory.- Specified by:
initializein interfaceThreadPool- Throws:
SchedulerConfigException
-
shutdown
public void shutdown()Terminate any worker threads in this thread group.Jobs currently in progress will complete.
- Specified by:
shutdownin interfaceThreadPool
-
runInThread
Run the givenRunnableobject 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 timesrunInThread(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
-