• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java SoftReferenceObjectPool类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中org.apache.commons.pool.impl.SoftReferenceObjectPool的典型用法代码示例。如果您正苦于以下问题:Java SoftReferenceObjectPool类的具体用法?Java SoftReferenceObjectPool怎么用?Java SoftReferenceObjectPool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

SoftReferenceObjectPool类属于org.apache.commons.pool.impl包,在下文中一共展示了SoftReferenceObjectPool类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: setupObjectPool

点赞 2

import org.apache.commons.pool.impl.SoftReferenceObjectPool; //导入依赖的package包/类
@Override
public void setupObjectPool() {
    objectPool = new SoftReferenceObjectPool<>(new BasePoolableObjectFactory<TestObject>() {
        @Override
        public TestObject makeObject() throws Exception {
            return new TestObject(true);
        }
    });
}
 

开发者ID:chrishantha,
项目名称:microbenchmarks,
代码行数:10,
代码来源:CommonsPoolSoftReferenceObjectPoolBenchmark.java

示例2: createObjectPool

点赞 2

import org.apache.commons.pool.impl.SoftReferenceObjectPool; //导入依赖的package包/类
/**
 * 建立物件池
 */
@Override
protected void createObjectPool() {
	// 設定factory
	SoftReferenceObjectPool<T> objectPool = new SoftReferenceObjectPool<T>(getPoolableCacheFactory());
	this.objectPool = objectPool;
}
 

开发者ID:mixaceh,
项目名称:openyu-commons,
代码行数:10,
代码来源:SoftReferenceCacheFactoryImpl.java

示例3: setUpBeforeClass

点赞 2

import org.apache.commons.pool.impl.SoftReferenceObjectPool; //导入依赖的package包/类
@BeforeClass
public static void setUpBeforeClass() throws Exception {
	pool = new SoftReferenceObjectPool<Object>(new PoolableObjectFactory<Object>() {

		int counter;

		public Object makeObject() throws Exception {
			return String.valueOf(counter++);
		}

		@Override
		public void destroyObject(Object paramT) throws Exception {
			// TODO Auto-generated method stub

		}

		@Override
		public boolean validateObject(Object paramT) {
			return true;
		}

		@Override
		public void activateObject(Object paramT) throws Exception {
			// TODO Auto-generated method stub

		}

		@Override
		public void passivateObject(Object paramT) throws Exception {
			// TODO Auto-generated method stub

		}
	});
}
 

开发者ID:mixaceh,
项目名称:openyu-commons,
代码行数:35,
代码来源:SoftReferenceObjectPoolTest.java

示例4: createPool

点赞 2

import org.apache.commons.pool.impl.SoftReferenceObjectPool; //导入依赖的package包/类
public ObjectPool<T> createPool() throws IllegalStateException {
	return new SoftReferenceObjectPool<T>(factory);
}
 

开发者ID:mixaceh,
项目名称:openyu-commons,
代码行数:4,
代码来源:SoftReferenceObjectPoolFactory.java

示例5: testPOFReturnObjectUsages

点赞 2

import org.apache.commons.pool.impl.SoftReferenceObjectPool; //导入依赖的package包/类
public void testPOFReturnObjectUsages() throws Exception {
    final MethodCallPoolableObjectFactory factory = new MethodCallPoolableObjectFactory();
    final ObjectPool pool;
    try {
        pool = makeEmptyPool(factory);
    } catch (UnsupportedOperationException uoe) {
        return; // test not supported
    }
    final List expectedMethods = new ArrayList();
    Object obj;

    /// Test correct behavior code paths
    obj = pool.borrowObject();
    clear(factory, expectedMethods);

    // returned object should be passivated
    pool.returnObject(obj);
    // StackObjectPool, SoftReferenceObjectPool also validate on return
    if (pool instanceof StackObjectPool || 
            pool instanceof SoftReferenceObjectPool) {
        expectedMethods.add(new MethodCall(
                "validateObject", obj).returned(Boolean.TRUE));
    }
    expectedMethods.add(new MethodCall("passivateObject", obj));
    assertEquals(expectedMethods, factory.getMethodCalls());

    //// Test exception handling of returnObject
    reset(pool, factory, expectedMethods);
    pool.addObject();
    pool.addObject();
    pool.addObject();
    assertEquals(3, pool.getNumIdle());
    // passivateObject should swallow exceptions and not add the object to the pool
    obj = pool.borrowObject();
    pool.borrowObject();
    assertEquals(1, pool.getNumIdle());
    assertEquals(2, pool.getNumActive());
    clear(factory, expectedMethods);
    factory.setPassivateObjectFail(true);
    pool.returnObject(obj);
    // StackObjectPool, SoftReferenceObjectPool also validate on return
    if (pool instanceof StackObjectPool || 
            pool instanceof SoftReferenceObjectPool) {
        expectedMethods.add(new MethodCall(
                "validateObject", obj).returned(Boolean.TRUE));
    }
    expectedMethods.add(new MethodCall("passivateObject", obj));
    removeDestroyObjectCall(factory.getMethodCalls()); // The exact timing of destroyObject is flexible here.
    assertEquals(expectedMethods, factory.getMethodCalls());
    assertEquals(1, pool.getNumIdle());   // Not returned
    assertEquals(1, pool.getNumActive()); // But not in active count

    // destroyObject should swallow exceptions too
    reset(pool, factory, expectedMethods);
    obj = pool.borrowObject();
    clear(factory, expectedMethods);
    factory.setPassivateObjectFail(true);
    factory.setDestroyObjectFail(true);
    pool.returnObject(obj);
}
 

开发者ID:WhiteBearSolutions,
项目名称:WBSAirback,
代码行数:61,
代码来源:TestObjectPool.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)