Jakarta Commons——对象池
来源:互联网 发布:人工智能预测彩票 编辑:程序博客网 时间:2024/06/05 21:52
作用
主要提供对象池的服务, 需要:
client(从池中取得对象和放回对象);
ObjectFactory继承于BasePoolableObjectFactory,用于激活和创建对象;
new ReaderUtil(new StackObjectPool(new StringBufferFactory()))
基本组件
ObjectPool
ObjectPool
defines a trivially simple pooling interface:
public interface ObjectPool {
Object borrowObject();
void returnObject(Object borrowed);
}
Some client classes won't integrate with Pool any more than this. Clients written to this interface can use arbitraryObjectPool
implementations interchangeably.
BaseObjectPool
provides an abstract base implementation of ObjectPool
. Clients are encouraged but not required to extendBaseObjectPool
for newObjectPool
implementations.
KeyedObjectPool
defines a similar interface for pools composed of heterogeneous objects:
public interface KeyedObjectPool {
Object borrowObject(Object key);
void returnObject(Object key, Object borrowed);
}
PoolableObjectFactory
The Pool package makes it possible separate the way in which instances are pooled from the way in which instances are created and destroyed.PoolableObjectFactory
supports this by providing a generic interface for the lifecycle of a pooled object:
public interface PoolableObjectFactory {
Object makeObject();
void activateObject(Object obj);
void passivateObject(Object obj);
boolean validateObject(Object obj);
void destroyObject(Object obj);
}
ObjectPool
implementations may be written to accept arbitraryPoolableObjectFactory
s. This makes is possible for clients to select pooling-behavior distinct from the kinds of objects that are pooled.
BasePoolableObjectFactory
provides an abstract base implementation of PoolableObjectFactory
that makes implementations a snap.
KeyedPoolableObjectFactory
defines a similar interface for KeyedObjectPool
s:
public interface KeyedPoolableObjectFactory {
Object makeObject(Object key);
void activateObject(Object key, Object obj);
void passivateObject(Object key, Object obj);
boolean validateObject(Object key, Object obj);
void destroyObject(Object key, Object obj);
}
BaseKeyedPoolableObjectFactory
provides an abstract base implementation of KeyedPoolableObjectFactory
that makes implementations a snap.
The org.apache.commons.pool.impl package provides somePool implementations.
StackObjectPool
StackObjectPool
will pool a finite number of "idle" instances, but will create new instances a needed in order to support high demand.
StackKeyedObjectPool
offers the same behavior for keyed pools.
GenericObjectPool
GenericObjectPool
provides a wide variety of configuration options, including the ability to cap the number of idle or active instances, to evict instances as they sit idle in the pool, etc.
GenericKeyedObjectPool
offers the same behavior for keyed pools.
SoftReferenceObjectPool
SoftReferenceObjectPool
can grow as needed, but allows the garbage collector to evict idle instances from the pool as needed.
- Jakarta Commons——对象池
- Jakarta commons——概述
- Jakarta commons——Lang
- Jakarta commons——Collections
- Jakarta Commons——IO
- Jakarta Commons——Validator
- Jakarta Commons——Net
- Jakarta Commons——DBUtils
- Jakarta Commons——BeanUtils
- Jakarta Commons——Digester
- Jakarta Commons——Discovery
- Jakarta Commons —— Configuration
- Jakarta Commons Pool 对象池 使用,测试
- Jakarta Commons————HttpClient
- Jakarta Commons(零)——介绍
- Jakarta Commons——数学计算
- Jakarta Commons——其他包
- 使用Jakarta Commons Pool处理对象池化
- lp_solve 规范
- 鲜为人知的软件项目管理原则(转载)
- Jakarta Commons——DBUtils
- XML和HTML常用转义字符
- Yahoo,Msn,Skype,QQ,阿里旺旺,网页聊天,网页链接,在线聊天链接接口调用
- Jakarta Commons——对象池
- 总结一下网站注入与防范的方法
- eclipse 工具
- 【规范】编程注释规范
- C++指针存储结构
- 替换字符串中间的某些字符
- 较全面的主流浏览器CSS BUG兼容汇总
- C++函数参数和返回值三种传递方式
- android 共享全局数据