本文整理汇总了Java中java.util.concurrent.ArrayBlockingQueue.clear方法的典型用法代码示例。如果您正苦于以下问题:Java ArrayBlockingQueue.clear方法的具体用法?Java ArrayBlockingQueue.clear怎么用?Java ArrayBlockingQueue.clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.ArrayBlockingQueue
的用法示例。
在下文中一共展示了ArrayBlockingQueue.clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testClear
import java.util.concurrent.ArrayBlockingQueue; //导入方法依赖的package包/类
/**
* clear removes all elements
*/
public void testClear() {
int size = ThreadLocalRandom.current().nextInt(1, 5);
ArrayBlockingQueue q = populatedQueue(size, size, 2 * size, false);
int capacity = size + q.remainingCapacity();
q.clear();
assertTrue(q.isEmpty());
assertEquals(0, q.size());
assertEquals(capacity, q.remainingCapacity());
q.add(one);
assertFalse(q.isEmpty());
assertTrue(q.contains(one));
q.clear();
assertTrue(q.isEmpty());
}
示例2: clear_willClearItrs
import java.util.concurrent.ArrayBlockingQueue; //导入方法依赖的package包/类
public void clear_willClearItrs() {
boolean fair = rnd.nextBoolean();
int capacity = rnd.nextInt(2, 10);
ArrayBlockingQueue q = new ArrayBlockingQueue(capacity, fair);
randomizePutIndex(q);
List<Iterator> its = new ArrayList<>();
for (int i = 0; i < capacity; i++)
assertTrue(q.add(i));
assertNull(itrs(q));
for (int i = 0; i < capacity; i++) {
its.add(q.iterator());
assertEquals(trackedIterators(q), its);
q.poll();
q.add(capacity + i);
}
q.clear();
assertNull(itrs(q));
int j = 0;
for (Iterator it : its) {
assertTrue(isDetached(it));
if (rnd.nextBoolean()) assertTrue(it.hasNext());
if (rnd.nextBoolean()) {
assertEquals(it.next(), j);
assertIteratorExhausted(it);
}
j++;
}
}