当前位置: 首页>>代码示例>>Java>>正文


Java ConcurrentLinkedQueueCollection类代码示例

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


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

示例1: setupObjectPool

import org.vibur.objectpool.util.ConcurrentLinkedQueueCollection; //导入依赖的package包/类
@Override
public void setupObjectPool() {
    objectPool = new ConcurrentPool<>(new ConcurrentLinkedQueueCollection<>(), new PoolObjectFactory<TestObject>() {

        @Override
        public TestObject create() {
            return new TestObject(true);
        }

        @Override
        public boolean readyToTake(TestObject obj) {
            return true;
        }

        @Override
        public boolean readyToRestore(TestObject obj) {
            return true;
        }

        @Override
        public void destroy(TestObject obj) {

        }
    }, 1, poolSize, false);

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

示例2: testSimpleTakes

import org.vibur.objectpool.util.ConcurrentLinkedQueueCollection; //导入依赖的package包/类
@Test
public void testSimpleTakes() {
    pool = new ConcurrentPool<>(new ConcurrentLinkedQueueCollection<>(), new SimpleObjectFactory(), 1, 3, false);

    Object obj1 = pool.take();
    Object obj2 = pool.take();
    Object obj3 = pool.take();
    Object obj4 = pool.tryTake();

    assertNotNull(obj1);
    assertNotNull(obj2);
    assertNotNull(obj3);
    assertNull(obj4);

    pool.restore(obj1);
    pool.restore(obj2);
    pool.restore(obj3);

    exception.expect(NullPointerException.class);
    pool.restore(null);
}
 
开发者ID:vibur,项目名称:vibur-object-pool,代码行数:22,代码来源:ConcurrentPoolTest.java

示例3: testInterrupted

import org.vibur.objectpool.util.ConcurrentLinkedQueueCollection; //导入依赖的package包/类
@Test
public void testInterrupted() {
    pool = new ConcurrentPool<>(new ConcurrentLinkedQueueCollection<>(), new SimpleObjectFactory(), 1, 3, false);

    Thread.currentThread().interrupt();
    Object obj1 = pool.take();

    assertNull(obj1);
    assertTrue(Thread.interrupted()); // clears the interrupted flag in order to not affect subsequent tests
}
 
开发者ID:vibur,项目名称:vibur-object-pool,代码行数:11,代码来源:ConcurrentPoolTest.java

示例4: testTimeWaited

import org.vibur.objectpool.util.ConcurrentLinkedQueueCollection; //导入依赖的package包/类
@Test
public void testTimeWaited() {
    pool = new ConcurrentPool<>(new ConcurrentLinkedQueueCollection<>(), new SimpleObjectFactory(), 1, 2, false);

    // takes one object and test
    long[] timeWaited = {-1};
    Object obj1 = pool.take(timeWaited);

    assertNotNull(obj1);
    assertTrue(timeWaited[0] >= 0);
}
 
开发者ID:vibur,项目名称:vibur-object-pool,代码行数:12,代码来源:ConcurrentPoolTest.java

示例5: testSimpleMetrics

import org.vibur.objectpool.util.ConcurrentLinkedQueueCollection; //导入依赖的package包/类
@Test
public void testSimpleMetrics() {
    pool = new ConcurrentPool<>(new ConcurrentLinkedQueueCollection<>(), new SimpleObjectFactory(), 1, 10, false);

    // tests the initial pool state
    assertFalse(pool.isTerminated());
    assertEquals(1, pool.initialSize());
    assertEquals(10, pool.maxSize());

    assertEquals(1, pool.createdTotal());
    assertEquals(1, pool.remainingCreated());
    assertEquals(10, pool.remainingCapacity());
    assertEquals(0, pool.taken());

    // takes one object and test
    Object obj1 = pool.take();
    assertNotNull(obj1);
    assertEquals(1, pool.createdTotal());
    assertEquals(0, pool.remainingCreated());
    assertEquals(9, pool.remainingCapacity());
    assertEquals(1, pool.taken());

    // restores one object and test
    pool.restore(obj1);
    assertEquals(1, pool.createdTotal());
    assertEquals(1, pool.remainingCreated());
    assertEquals(10, pool.remainingCapacity());
    assertEquals(0, pool.taken());

    // takes all objects and test
    Object[] objs = new Object[10];
    for (int i = 0; i < 10; i++) {
        objs[i] = pool.take();
        assertNotNull(objs[i]);
    }
    obj1 = pool.tryTake();
    assertNull(obj1);
    assertEquals(10, pool.createdTotal());
    assertEquals(0, pool.remainingCreated());
    assertEquals(0, pool.remainingCapacity());
    assertEquals(10, pool.taken());

    // restores the first 6 objects and test
    for (int i = 0; i < 6; i++) {
        pool.restore(objs[i]);
    }
    assertEquals(10, pool.createdTotal());
    assertEquals(6, pool.remainingCreated());
    assertEquals(6, pool.remainingCapacity());
    assertEquals(4, pool.taken());

    // restores the remaining 4 objects and test
    for (int i = 6; i < 10; i++) {
        pool.restore(objs[i]);
    }
    assertEquals(10, pool.createdTotal());
    assertEquals(10, pool.remainingCreated());
    assertEquals(10, pool.remainingCapacity());
    assertEquals(0, pool.taken());

    // terminates the pool and test
    pool.terminate();
    assertTrue(pool.isTerminated());
    assertEquals(1, pool.initialSize());
    assertEquals(10, pool.maxSize());

    assertEquals(0, pool.createdTotal());
    assertEquals(0, pool.remainingCreated());
    assertEquals(0, pool.remainingCapacity());
    assertEquals(0, pool.taken());
}
 
开发者ID:vibur,项目名称:vibur-object-pool,代码行数:72,代码来源:ConcurrentPoolTest.java


注:本文中的org.vibur.objectpool.util.ConcurrentLinkedQueueCollection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。