public class ZeroSizeThreadPool extends Object implements IThreadPool
This is class is a simple implementation of a zero size thread pool, based on
the interface.
IThreadPool
The pool has zero Threads and does not grow or shrink based on
demand. Which means it is obviously not useful for most scenarios. When it
may be useful is to prevent creating any worker threads at all - which may be
desirable for the sole purpose of preserving system resources in the case
where the scheduler instance only exists in order to schedule jobs, but which
will never execute jobs (e.g. will never have start() called on it).
| Constructor and Description |
|---|
ZeroSizeThreadPool() |
| Modifier and Type | Method and Description |
|---|---|
int |
blockForAvailableThreads()
Determines the number of threads that are currently available in in the
pool.
|
int |
getPoolSize()
Get the current number of threads in the
ThreadPool. |
void |
initialize()
Must be called before the
ThreadPool is used, in order to give
the it a chance to initialize. |
boolean |
runInThread(Runnable runnable)
Execute the given
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 |
shutdown() |
void |
shutdown(boolean waitForJobsToComplete)
Called by the QuartzScheduler to inform the
ThreadPool that it
should free up all of it's resources because the scheduler is shutting
down. |
public int getPoolSize()
IThreadPool
Get the current number of threads in the ThreadPool.
getPoolSize 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 IThreadPoolSchedulerConfigExceptionpublic void shutdown()
public void shutdown(boolean waitForJobsToComplete)
IThreadPool
Called by the QuartzScheduler to inform the ThreadPool that it
should free up all of it's resources because the scheduler is shutting
down.
shutdown in interface IThreadPoolpublic boolean runInThread(Runnable runnable)
IThreadPool
Execute the given in the next
available RunnableThread.
The implementation of this interface should not throw exceptions unless
there is a serious problem (i.e. a serious misconfiguration). If there are
no immediately available threads false should be returned.
runInThread in interface IThreadPoolpublic 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 IThreadPoolpublic 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 IThreadPoolCopyright © 2016–2021 Philip Helger. All rights reserved.