本文整理汇总了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);
}
示例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);
}
示例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
}
示例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);
}
示例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());
}