本文整理汇总了Java中java.util.concurrent.LinkedBlockingQueue.put方法的典型用法代码示例。如果您正苦于以下问题:Java LinkedBlockingQueue.put方法的具体用法?Java LinkedBlockingQueue.put怎么用?Java LinkedBlockingQueue.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.LinkedBlockingQueue
的用法示例。
在下文中一共展示了LinkedBlockingQueue.put方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDrainToWithActivePut
import java.util.concurrent.LinkedBlockingQueue; //导入方法依赖的package包/类
/**
* drainTo empties full queue, unblocking a waiting put.
*/
public void testDrainToWithActivePut() throws InterruptedException {
final LinkedBlockingQueue q = populatedQueue(SIZE);
Thread t = new Thread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
q.put(new Integer(SIZE + 1));
}});
t.start();
ArrayList l = new ArrayList();
q.drainTo(l);
assertTrue(l.size() >= SIZE);
for (int i = 0; i < SIZE; ++i)
assertEquals(l.get(i), new Integer(i));
t.join();
assertTrue(q.size() + l.size() >= SIZE);
}
示例2: testPut
import java.util.concurrent.LinkedBlockingQueue; //导入方法依赖的package包/类
/**
* all elements successfully put are contained
*/
public void testPut() throws InterruptedException {
LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE);
for (int i = 0; i < SIZE; ++i) {
Integer x = new Integer(i);
q.put(x);
assertTrue(q.contains(x));
}
assertEquals(0, q.remainingCapacity());
}