Package edu.jas.util
Class ThreadPool
java.lang.Object
edu.jas.util.ThreadPool
Thread pool using stack / list workpile.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final boolean
(package private) static final int
Default number of threads to use.protected int
Number of idle workers.protected LinkedList
<Runnable> Work queue / stack.private static final org.apache.logging.log4j.Logger
protected boolean
Shutdown request.(package private) final int
Number of threads to use.protected StrategyEnumeration
protected PoolThread[]
Array of workers. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new ThreadPool with strategy StrategyEnumeration.FIFO and size DEFAULT_SIZE.ThreadPool
(int size) Constructs a new ThreadPool with strategy StrategyEnumeration.FIFO.ThreadPool
(StrategyEnumeration strategy) Constructs a new ThreadPool with size DEFAULT_SIZE.ThreadPool
(StrategyEnumeration strategy, int size) Constructs a new ThreadPool. -
Method Summary
Modifier and TypeMethodDescriptionvoid
adds a job to the workpile.int
cancel()
Cancels the threads.protected Runnable
getJob()
get a job for processing.int
number of worker threads.get used strategy.boolean
hasJobs()
check if there are jobs for processing.boolean
hasJobs
(int n) check if there are more than n jobs for processing.void
init()
thread initialization and start.void
Terminates the threads.toString()
toString.
-
Field Details
-
DEFAULT_SIZE
static final int DEFAULT_SIZEDefault number of threads to use.- See Also:
-
size
final int sizeNumber of threads to use. -
workers
Array of workers. -
idleworkers
protected int idleworkersNumber of idle workers. -
shutdown
protected volatile boolean shutdownShutdown request. -
jobstack
Work queue / stack. -
strategy
-
logger
private static final org.apache.logging.log4j.Logger logger -
debug
private static final boolean debug
-
-
Constructor Details
-
ThreadPool
public ThreadPool()Constructs a new ThreadPool with strategy StrategyEnumeration.FIFO and size DEFAULT_SIZE. -
ThreadPool
Constructs a new ThreadPool with size DEFAULT_SIZE.- Parameters:
strategy
- for job processing.
-
ThreadPool
public ThreadPool(int size) Constructs a new ThreadPool with strategy StrategyEnumeration.FIFO.- Parameters:
size
- of the pool.
-
ThreadPool
Constructs a new ThreadPool.- Parameters:
strategy
- for job processing.size
- of the pool.
-
-
Method Details
-
init
public void init()thread initialization and start. -
toString
toString. -
getNumber
public int getNumber()number of worker threads. -
getStrategy
get used strategy. -
terminate
public void terminate()Terminates the threads. -
cancel
public int cancel()Cancels the threads. -
addJob
adds a job to the workpile.- Parameters:
job
-
-
getJob
get a job for processing.- Throws:
InterruptedException
-
hasJobs
public boolean hasJobs()check if there are jobs for processing. -
hasJobs
public boolean hasJobs(int n) check if there are more than n jobs for processing.- Parameters:
n
- Integer- Returns:
- true, if there are possibly more than n jobs.
-