本文整理汇总了Java中java.util.concurrent.LinkedTransferQueue.drainTo方法的典型用法代码示例。如果您正苦于以下问题:Java LinkedTransferQueue.drainTo方法的具体用法?Java LinkedTransferQueue.drainTo怎么用?Java LinkedTransferQueue.drainTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.LinkedTransferQueue
的用法示例。
在下文中一共展示了LinkedTransferQueue.drainTo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDrainTo
import java.util.concurrent.LinkedTransferQueue; //导入方法依赖的package包/类
/**
* drainTo(c) empties queue into another collection c
*/
public void testDrainTo() {
LinkedTransferQueue q = populatedQueue(SIZE);
ArrayList l = new ArrayList();
q.drainTo(l);
assertEquals(0, q.size());
assertEquals(SIZE, l.size());
for (int i = 0; i < SIZE; ++i) {
assertEquals(i, l.get(i));
}
q.add(zero);
q.add(one);
assertFalse(q.isEmpty());
assertTrue(q.contains(zero));
assertTrue(q.contains(one));
l.clear();
q.drainTo(l);
assertEquals(0, q.size());
assertEquals(2, l.size());
for (int i = 0; i < 2; ++i) {
assertEquals(i, l.get(i));
}
}
示例2: testDrainToN
import java.util.concurrent.LinkedTransferQueue; //导入方法依赖的package包/类
/**
* drainTo(c, n) empties first min(n, size) elements of queue into c
*/
public void testDrainToN() {
LinkedTransferQueue q = new LinkedTransferQueue();
for (int i = 0; i < SIZE + 2; ++i) {
for (int j = 0; j < SIZE; j++) {
assertTrue(q.offer(j));
}
ArrayList l = new ArrayList();
q.drainTo(l, i);
int k = (i < SIZE) ? i : SIZE;
assertEquals(k, l.size());
assertEquals(SIZE - k, q.size());
for (int j = 0; j < k; ++j)
assertEquals(j, l.get(j));
do {} while (q.poll() != null);
}
}
示例3: testDrainToWithActivePut
import java.util.concurrent.LinkedTransferQueue; //导入方法依赖的package包/类
/**
* drainTo(c) empties full queue, unblocking a waiting put.
*/
public void testDrainToWithActivePut() throws InterruptedException {
final LinkedTransferQueue q = populatedQueue(SIZE);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() {
q.put(SIZE + 1);
}});
ArrayList l = new ArrayList();
q.drainTo(l);
assertTrue(l.size() >= SIZE);
for (int i = 0; i < SIZE; ++i)
assertEquals(i, l.get(i));
awaitTermination(t);
assertTrue(q.size() + l.size() >= SIZE);
}