public class ThreadPool extends Object
This thread pool maintains a number of threads that run the tasks from a task queue one by one. The tasks are handled in asynchronous mode, which means it will not block the main thread to proceed while the task is being processed by the thread pool.
This thread pool has a fixed size of threads. It maintains all the tasks to be executed in a task queue. Each thread then in turn gets a task from the queue to execute. If the tasks in the task queue reaches a certain number(the threshold value), it will log an error message and ignore the new incoming tasks until the number of un-executed tasks is less than the threshold value. This guarantees the thread pool will not use up the system resources under heavy load.
Constructor and Description |
---|
ThreadPool(String name,
int poolSize)
Constructs a thread pool with given parameters.
|
Modifier and Type | Method and Description |
---|---|
void |
run(Runnable task)
Runs a user defined task.
|
void |
shutdown()
Shuts down the ThreadPool.
|
public ThreadPool(String name, int poolSize)
name
- name of the thread pool.poolSize
- the thread pool size, indicates how many threads are created
in the pool.public final void run(Runnable task) throws ThreadPoolException
task
- user defined task.ThreadPoolException
public void shutdown()
Copyright © 2010–2025 Open Identity Platform Community. All rights reserved.