E - 放入池中的资源类型public class LinkedPool<E> extends Object
| 限定符和类型 | 类和说明 |
|---|---|
static class |
LinkedPool.Element<E>
队列项
|
| 限定符和类型 | 字段和说明 |
|---|---|
protected static org.slf4j.Logger |
_Logger
日志记录器
|
protected static Timer |
_Timer
用于检查处理队列的定时器
|
protected int |
m_CreateTimes
创建计数
|
protected cn.weforward.common.util.LinkedPool.IdleChecker |
m_IdleChecker
定时检查可用表空闲项
|
protected AtomicInteger |
m_InQueue
在等待及处理中的数
|
protected LinkedPool.Element<E> |
m_InUseChain
使用中的资源表(链表首项)
|
protected int |
m_InUseCount
当前正在使用(链表中)的项数
|
protected cn.weforward.common.util.LinkedPool.LongtimeChecker |
m_LongtimeChecker
定时检查使用表占用过长项
|
protected int |
m_MaxSize
池的最大资源项数
|
protected String |
m_Name
名称
|
protected int |
m_QueueLengthMax
最大等待数(不包含当前并发处理中)
|
protected int |
m_QueueTimeout
最大等待(进入队列)的时间(毫秒)
|
protected LinkedPool.Element<E> |
m_ResourceChain
可使用的资源表(链表首项)
|
static int |
STATE_DELAY
状态 - 检查到使用时间有点长(1/2的时间过长值)
|
static int |
STATE_EMPTY
状态 - 空的
|
static int |
STATE_IDLE
状态 - 空闲的
|
static int |
STATE_INUSE
状态 - 使用中
|
static int |
STATE_LONGTIME
状态 - 占用太长
|
static int |
STATE_OLD
状态 - 空闲后未释放的项,还一直空闲
|
| 构造器和说明 |
|---|
LinkedPool(int maxSize,
String name)
构造池
|
| 限定符和类型 | 方法和说明 |
|---|---|
int |
abort()
关闭在使用中的资源(异步)
|
void |
close()
关闭池
|
String |
dump() |
int |
getCreateTimes() |
int |
getIdle() |
int |
getInQueue()
在等待及处理中的项数
|
int |
getInUseCount()
使用中的项数
|
int |
getLongtime() |
int |
getMaxSize()
池的最大项数
|
String |
getName()
名称
|
int |
getQueueLengthMax() |
int |
getQueueTimeout() |
LinkedPool.Element<E> |
getUsing(E resource)
查询正在使用项
|
void |
offer(E resource)
把用完的资源放回池中
|
void |
offer(E resource,
boolean empty)
把用完的资源放回池
|
protected void |
onCloseElement(LinkedPool.Element<E> element)
关闭资源项
|
protected E |
onCreateElement()
子类覆盖此方法动态创建池的资源项
|
protected void |
onIdle(LinkedPool.Element<E> element,
int idle)
项空闲
|
protected void |
onLongtime(LinkedPool.Element<E> element,
int useup)
资源项占用时间过长
|
E |
poll()
由池取得队列项,通常使用的代码为:
E handler=null;
try {
handler=queue.poll();
if(null==handler){
throw BusyException("服务器忙");
}
对handler的业务调用...
}finally {
queue.offer(handler);
}
|
void |
setIdle(int seconds)
设置池中项空闲时间检查
|
void |
setLongtime(int seconds)
使用池中项的(检查)超时值
|
void |
setQueueLengthMax(int size)
设置最大排队项数(=池的最大项数+等待的项数)
|
void |
setQueueTimeout(int mills)
在池中取得空闲项的排队超时值
|
void |
shutdown()
关停池,不允许继续分配资源
|
String |
toString() |
StringBuilder |
toString(StringBuilder builder) |
public static final int STATE_IDLE
public static final int STATE_INUSE
public static final int STATE_EMPTY
public static final int STATE_OLD
public static final int STATE_DELAY
public static final int STATE_LONGTIME
protected static final org.slf4j.Logger _Logger
protected static final Timer _Timer
protected int m_QueueTimeout
protected int m_QueueLengthMax
protected int m_MaxSize
protected LinkedPool.Element<E> m_ResourceChain
protected LinkedPool.Element<E> m_InUseChain
protected int m_InUseCount
protected final AtomicInteger m_InQueue
protected final String m_Name
protected volatile int m_CreateTimes
protected cn.weforward.common.util.LinkedPool.IdleChecker m_IdleChecker
protected cn.weforward.common.util.LinkedPool.LongtimeChecker m_LongtimeChecker
public LinkedPool(int maxSize,
String name)
maxSize - 池的最大项name - 指定池的名称public String getName()
public void close()
public int abort()
public void shutdown()
protected E onCreateElement()
protected void onCloseElement(LinkedPool.Element<E> element)
element - 要关闭的项protected void onIdle(LinkedPool.Element<E> element, int idle)
element - 空闲的项idle - 空闲值(毫秒)protected void onLongtime(LinkedPool.Element<E> element, int useup)
element - 耗时的资源项useup - 使用时间(毫秒)public int getMaxSize()
public void setQueueLengthMax(int size)
size - 最大排队数,必须不小于QueueMaxpublic int getQueueLengthMax()
public void setQueueTimeout(int mills)
mills - 超时值(单位为毫秒),若=0为不等待public int getQueueTimeout()
public void setIdle(int seconds)
seconds - 空闲时间(单位为秒),若=0为不检查空闲public int getIdle()
public void setLongtime(int seconds)
seconds - 超时值(单位为秒),若为0则不检查public int getLongtime()
public int getInQueue()
public int getCreateTimes()
public int getInUseCount()
public E poll()
E handler=null;
try {
handler=queue.poll();
if(null==handler){
throw BusyException("服务器忙");
}
对handler的业务调用...
}finally {
queue.offer(handler);
}
public void offer(E resource)
resource - 用完的资源项public void offer(E resource, boolean empty)
resource - 用完的资源项empty - 是否在池中清空此项public LinkedPool.Element<E> getUsing(E resource)
resource - 要查询的资源项public StringBuilder toString(StringBuilder builder)
public String dump()
Copyright © 2022. All rights reserved.