Class ThreadPool
java.lang.Object
edu.jas.util.ThreadPool
Thread pool using stack / list workpile.
- Author:
- Akitoshi Yoshida, Heinz Kredel
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intNumber of idle workers.protected LinkedList<Runnable> Work queue / stack.protected booleanShutdown request.protected StrategyEnumerationprotected edu.jas.util.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 TypeMethodDescriptionvoidadds a job to the workpile.intcancel()Cancels the threads.protected RunnablegetJob()get a job for processing.intnumber of worker threads.get used strategy.booleanhasJobs()check if there are jobs for processing.booleanhasJobs(int n) check if there are more than n jobs for processing.voidinit()thread initialization and start.voidTerminates the threads.toString()toString.
-
Field Details
-
workers
protected edu.jas.util.PoolThread[] workersArray of workers. -
idleworkers
protected int idleworkersNumber of idle workers. -
shutdown
protected volatile boolean shutdownShutdown request. -
jobstack
Work queue / stack. -
strategy
-
-
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
-
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
-
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.
-