public class ThreadPool extends IThreadPool
Modifier and Type | Class and Description |
---|---|
static class |
ThreadPool.PoolWorkerStrategyFactory
Factory class for worker strategy
|
static class |
ThreadPool.ThreadPoolState
states of the thread pool.
|
static class |
ThreadPool.ThreadPoolType |
protected class |
ThreadPool.Worker
Worker class.
|
NUM_THREADS
Modifier | Constructor and Description |
---|---|
protected |
ThreadPool(IStructure<PTask> taskPool,
int numOfThreads,
ThreadPool.ThreadPoolType type)
prevent from creating thread pools via constructor
|
Modifier and Type | Method and Description |
---|---|
void |
add(PTask item)
add a task to the pool
|
void |
add(PTask item,
int threadId)
add a task to the pool
|
int |
getPoolSize() |
ThreadPool.ThreadPoolState |
getState()
Get current state of the thread pool
|
static ThreadPool |
getThreadPool()
returns the current thread pool
|
static ThreadPool |
initialize()
initialize thread pool, default initialization
|
static ThreadPool |
initialize(int num)
initialize thread pool with number of threads
|
static ThreadPool |
initialize(IStructure<PTask> taskPool)
initialize thread pool with specific task pool
|
static ThreadPool |
initialize(IStructure<PTask> taskPool,
int numOfThreads)
initialize thread pool with specific task pool and number of threads
|
static ThreadPool |
initialize(IStructure<PTask> taskPool,
int numOfThreads,
ThreadPool.ThreadPoolType type)
initialize thread pool with specific task pool and number of threads
|
static ThreadPool[] |
initialize(IStructure<PTask> taskPool1,
int numOfThreads1,
ThreadPool.ThreadPoolType type1,
IStructure<PTask> taskPool2,
int numOfThreads2,
ThreadPool.ThreadPoolType type2)
create a double thread pool (two thread pool side by side)
|
static ThreadPool |
initialize(Scheduler.SchedulingStrategy taskPool,
int numOfThreads) |
static ThreadPool |
initialize(Scheduler.SchedulingStrategy taskPool,
int numOfThreads,
ThreadPool.ThreadPoolType type) |
void |
join()
wait for termination
|
static void |
killPool()
hard shutdown of thread pool
|
void |
shutdown()
shutdown the thread pool
|
void |
sleep()
Set thread pool to state sleep.
|
void |
start()
start the thread pool
|
void |
trigger()
trigger workers (used for the synchronization)
|
void |
weakUp()
Wake up the thread pool.
|
protected ThreadPool(IStructure<PTask> taskPool, int numOfThreads, ThreadPool.ThreadPoolType type)
taskPool
- numOfThreads
- public void start()
start
in class IThreadPool
public void shutdown() throws java.lang.InterruptedException
shutdown
in class IThreadPool
java.lang.InterruptedException
public void join() throws java.lang.InterruptedException
join
in class IThreadPool
java.lang.InterruptedException
public void sleep()
sleep
in class IThreadPool
public void weakUp()
weakUp
in class IThreadPool
public void trigger()
trigger
in class IThreadPool
public void add(PTask item)
add
in class IThreadPool
item
- public void add(PTask item, int threadId)
add
in class IThreadPool
item
- public int getPoolSize()
getPoolSize
in class IThreadPool
public static ThreadPool initialize() throws PoolExistsException, Scheduler.UnknownSchedulerException
PoolExistsException
Scheduler.UnknownSchedulerException
public static ThreadPool initialize(int num) throws PoolExistsException
num
- of threadsPoolExistsException
public static ThreadPool initialize(IStructure<PTask> taskPool) throws PoolExistsException
taskPool
- to be usedPoolExistsException
public static ThreadPool initialize(Scheduler.SchedulingStrategy taskPool, int numOfThreads) throws Scheduler.UnknownSchedulerException, PoolExistsException
public static ThreadPool initialize(Scheduler.SchedulingStrategy taskPool, int numOfThreads, ThreadPool.ThreadPoolType type) throws Scheduler.UnknownSchedulerException, PoolExistsException
public static ThreadPool initialize(IStructure<PTask> taskPool, int numOfThreads) throws PoolExistsException
taskPool
- to be usednumOfThreads
- PoolExistsException
public static ThreadPool initialize(IStructure<PTask> taskPool, int numOfThreads, ThreadPool.ThreadPoolType type) throws PoolExistsException
taskPool
- to be usednumOfThreads
- PoolExistsException
public static ThreadPool[] initialize(IStructure<PTask> taskPool1, int numOfThreads1, ThreadPool.ThreadPoolType type1, IStructure<PTask> taskPool2, int numOfThreads2, ThreadPool.ThreadPoolType type2)
taskPool1
- numOfThreads1
- type1
- taskPool2
- numOfThreads2
- type2
- public static void killPool()
public static ThreadPool getThreadPool()
public ThreadPool.ThreadPoolState getState()