public class ZeroSizeThreadPool extends Object implements ThreadPool
This is class is a simple implementation of a zero size thread pool, based on the
interface.
ThreadPool
The pool has zero Thread
s 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()
Create a new
ZeroSizeThreadPool . |
Modifier and Type | Method and Description |
---|---|
int |
blockForAvailableThreads()
Determines the number of threads that are currently available in in
the pool.
|
org.slf4j.Logger |
getLog() |
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 org.slf4j.Logger getLog()
public int getPoolSize()
ThreadPool
Get the current number of threads in the ThreadPool
.
getPoolSize
in interface ThreadPool
public void initialize() throws SchedulerConfigException
ThreadPool
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 ThreadPool
SchedulerConfigException
public void shutdown()
public void shutdown(boolean waitForJobsToComplete)
ThreadPool
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 ThreadPool
public boolean runInThread(Runnable runnable)
ThreadPool
Execute the given
in the next
available Runnable
Thread
.
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 ThreadPool
public int blockForAvailableThreads()
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.
blockForAvailableThreads
in interface ThreadPool
public void setInstanceId(String schedInstId)
ThreadPool
Inform the ThreadPool
of the Scheduler instance's Id,
prior to initialize being invoked.
setInstanceId
in interface ThreadPool
public void setInstanceName(String schedName)
ThreadPool
Inform the ThreadPool
of the Scheduler instance's name,
prior to initialize being invoked.
setInstanceName
in interface ThreadPool
Copyright 2001-2019, Terracotta, Inc.