SoftReferenceObjectPool:它使用ArrayList保存對象
_pool
SoftReferenceObjectPool對對象的數量沒有限制
以下代碼顯示了一個簡單的對象池工廠
public class PoolableObjectFactoryDemo implements PoolableObjectFactory {
private static AtomicInteger counter = new AtomicInteger(
public Object makeObject() throws Exception { //創建對象
Object obj = String
System
return obj;
}
public void activateObject(Object obj) throws Exception {
System
}
public void passivateObject(Object obj) throws Exception {
System
}
public boolean validateObject(Object obj) {
return true;
}
public void destroyObject(Object obj) throws Exception {
System
}
}
對象池的使用例子如下
[
From:http://tw.wingwit.com/Article/program/Java/gj/201311/27795.html