本文整理匯總了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());
}