本文整理汇总了Java中org.apache.commons.pool.ObjectPool.close方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectPool.close方法的具体用法?Java ObjectPool.close怎么用?Java ObjectPool.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.pool.ObjectPool
的用法示例。
在下文中一共展示了ObjectPool.close方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: close
import org.apache.commons.pool.ObjectPool; //导入方法依赖的package包/类
/**
* 關閉
*
* @throws CacheException
*/
public synchronized void close() throws CacheException {
if (this.closed) {
throw new CacheException("CacheFactory was already closed");
}
//
try {
// TODO cacheHolder 未清, 需用反射清除
this.closed = true;
ObjectPool<T> oldPool = this.objectPool;
this.objectPool = null;
if (oldPool != null) {
oldPool.close();
}
} catch (Exception ex) {
throw new CacheException("Cannot close pool", ex);
}
}
示例2: releaseAllResources
import org.apache.commons.pool.ObjectPool; //导入方法依赖的package包/类
/**
* Closes all managed pools.
*/
public void releaseAllResources()
{
synchronized (poolSynch)
{
Collection pools = poolMap.values();
poolMap = new HashMap(poolMap.size());
ObjectPool op = null;
for (Iterator iterator = pools.iterator(); iterator.hasNext();)
{
try
{
op = ((ObjectPool) iterator.next());
op.close();
}
catch (Exception e)
{
log.error("Exception occured while closing pool " + op, e);
}
}
}
super.releaseAllResources();
}
示例3: testAddObject
import org.apache.commons.pool.ObjectPool; //导入方法依赖的package包/类
public void testAddObject() throws Exception {
assertEquals("should be zero idle", 0, pool.getNumIdle());
pool.addObject();
assertEquals("should be one idle", 1, pool.getNumIdle());
assertEquals("should be zero active", 0, pool.getNumActive());
Object obj = pool.borrowObject();
assertEquals("should be zero idle", 0, pool.getNumIdle());
assertEquals("should be one active", 1, pool.getNumActive());
pool.returnObject(obj);
assertEquals("should be one idle", 1, pool.getNumIdle());
assertEquals("should be zero active", 0, pool.getNumActive());
ObjectPool op = new GenericObjectPool();
try {
op.addObject();
fail("Expected IllegalStateException when there is no factory.");
} catch (IllegalStateException ise) {
//expected
}
op.close();
}
示例4: removeDBPool
import org.apache.commons.pool.ObjectPool; //导入方法依赖的package包/类
/**
* Closes the database connection pool
*/
private void removeDBPool() {
final ObjectPool dbpool = getDBPool();
if (dbpool != null) {
try {
dbpool.close();
} catch (Throwable any) {
LOGGER.error("Unable to close the database connection pool", any);
messageOut(Resources.getString("errFailCloseDBPool", any.getMessage()),
STYLE_RED);
}
}
}
示例5: closePool
import org.apache.commons.pool.ObjectPool; //导入方法依赖的package包/类
public synchronized void closePool(String name) throws SQLException {
ObjectPool pool = (ObjectPool) _pools.get(name);
if (pool != null) {
_pools.remove(name);
try {
pool.close();
}
catch (Exception e) {
throw (SQLException) new SQLException("Error closing pool " + name).initCause(e);
}
}
}
示例6: testInitIdleCapacityExceeded
import org.apache.commons.pool.ObjectPool; //导入方法依赖的package包/类
/**
* Verifies that initIdleCapacity is not a hard limit, but maxIdle is.
*/
public void testInitIdleCapacityExceeded() throws Exception {
PoolableObjectFactory factory = new SimpleFactory();
ObjectPool pool = new StackObjectPool(factory, 2, 1);
pool.addObject();
pool.addObject();
assertEquals(2, pool.getNumIdle());
pool.close();
pool = new StackObjectPool(factory, 1, 2);
pool.addObject();
pool.addObject();
assertEquals(1, pool.getNumIdle());
}