public class ThreadPool extends Object implements Executor, DestroyableExt, Quotas.Governable, Nameable
| 限定符和类型 | 类和说明 |
|---|---|
static class |
ThreadPool.ThreadExt
池中的线程
|
| 限定符和类型 | 字段和说明 |
|---|---|
static org.slf4j.Logger |
_Logger |
protected AtomicInteger |
m_Concurrent
并发数(若为MIN_VALUE则不计算并发数且不受配额限制)
|
protected boolean |
m_Daemon
是否后台线程模式
|
protected String |
m_Name
名称
|
protected LinkedPool<ThreadPool.ThreadExt> |
m_Pool
池
|
protected Quotas |
m_Quotas
使用配额控制
|
| 构造器和说明 |
|---|
ThreadPool(int maxThreads,
String name)
创建线程池
|
ThreadPool(ThreadPool group)
使用配额共用的线程池
|
| 限定符和类型 | 方法和说明 |
|---|---|
ThreadPool |
byQuota()
启用独立配额限制并发线程数
|
void |
destroy()
执行清理
|
boolean |
destroySignal()
使用信号的方式进行清理(不能在其阻塞地执行清理)
|
String |
dump() |
protected void |
end(ThreadPool.ThreadExt thread,
boolean running)
任务执行完成,释放回池
|
void |
execute(Runnable handler) |
int |
getInQueue() |
int |
getMaxThreads() |
String |
getName()
同样(业务)场景的唯一名称
|
List<Thread> |
getRunThreads() |
int |
getThreads() |
void |
setDaemon(boolean daemon)
配置是否后台线程模式
|
void |
setIdle(int seconds)
设置线程空闲回收时间
|
void |
setLongtime(int seconds)
使用池中项的(检查)超时值
|
void |
setName(String name) |
void |
setNolimit(boolean nolimit)
指定是否不受配额限制
|
void |
setQueueLengthMax(int size)
设置最大排队项数(=池的最大项数+等待的项数)
|
void |
setQueueTimeout(int mills)
在池中取得空闲项的排队超时值
|
void |
setQuotas(Quotas quotas) |
void |
shutdown() |
String |
toString() |
String |
toString(String msg) |
public static final org.slf4j.Logger _Logger
protected LinkedPool<ThreadPool.ThreadExt> m_Pool
protected String m_Name
protected Quotas m_Quotas
protected AtomicInteger m_Concurrent
protected boolean m_Daemon
public ThreadPool(ThreadPool group)
group - 共用的池public ThreadPool(int maxThreads,
String name)
maxThreads - 最大线程数name - 名称public ThreadPool byQuota()
public void setName(String name)
public void setDaemon(boolean daemon)
public void setIdle(int seconds)
seconds - 空闲时间(单位为秒)public void setLongtime(int seconds)
seconds - 超时值(单位为秒)public void setQuotas(Quotas quotas)
public void setNolimit(boolean nolimit)
nolimit - 是否不受配额限制public void setQueueLengthMax(int size)
size - 最大排队数,必须不小于QueueMaxpublic void setQueueTimeout(int mills)
mills - 超时值(单位为毫秒),若=0为不等待public int getThreads()
public int getMaxThreads()
public int getInQueue()
protected void end(ThreadPool.ThreadExt thread, boolean running)
thread - 线程running - 是否继续运行public void shutdown()
public void destroy()
Destroyabledestroy 在接口中 Destroyablepublic boolean destroySignal()
DestroyableExtdestroySignal 在接口中 DestroyableExtpublic String dump()
Copyright © 2020. All rights reserved.