當前位置: 首頁>>代碼示例>>Java>>正文


Java DelayQueue.drainTo方法代碼示例

本文整理匯總了Java中java.util.concurrent.DelayQueue.drainTo方法的典型用法代碼示例。如果您正苦於以下問題:Java DelayQueue.drainTo方法的具體用法?Java DelayQueue.drainTo怎麽用?Java DelayQueue.drainTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.concurrent.DelayQueue的用法示例。


在下文中一共展示了DelayQueue.drainTo方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testDrainTo

import java.util.concurrent.DelayQueue; //導入方法依賴的package包/類
/**
 * drainTo(c) empties queue into another collection c
 */
public void testDrainTo() {
    DelayQueue q = new DelayQueue();
    PDelay[] elems = new PDelay[SIZE];
    for (int i = 0; i < SIZE; ++i) {
        elems[i] = new PDelay(i);
        q.add(elems[i]);
    }
    ArrayList l = new ArrayList();
    q.drainTo(l);
    assertEquals(0, q.size());
    for (int i = 0; i < SIZE; ++i)
        assertEquals(elems[i], l.get(i));
    q.add(elems[0]);
    q.add(elems[1]);
    assertFalse(q.isEmpty());
    assertTrue(q.contains(elems[0]));
    assertTrue(q.contains(elems[1]));
    l.clear();
    q.drainTo(l);
    assertEquals(0, q.size());
    assertEquals(2, l.size());
    for (int i = 0; i < 2; ++i)
        assertEquals(elems[i], l.get(i));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:28,代碼來源:DelayQueueTest.java

示例2: testDrainToWithActivePut

import java.util.concurrent.DelayQueue; //導入方法依賴的package包/類
/**
 * drainTo empties queue
 */
public void testDrainToWithActivePut() throws InterruptedException {
    final DelayQueue q = populatedQueue(SIZE);
    Thread t = new Thread(new CheckedRunnable() {
        public void realRun() {
            q.put(new PDelay(SIZE + 1));
        }});

    t.start();
    ArrayList l = new ArrayList();
    q.drainTo(l);
    assertTrue(l.size() >= SIZE);
    t.join();
    assertTrue(q.size() + l.size() >= SIZE);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:DelayQueueTest.java

示例3: testDrainToN

import java.util.concurrent.DelayQueue; //導入方法依賴的package包/類
/**
 * drainTo(c, n) empties first min(n, size) elements of queue into c
 */
public void testDrainToN() {
    for (int i = 0; i < SIZE + 2; ++i) {
        DelayQueue q = populatedQueue(SIZE);
        ArrayList l = new ArrayList();
        q.drainTo(l, i);
        int k = (i < SIZE) ? i : SIZE;
        assertEquals(SIZE - k, q.size());
        assertEquals(k, l.size());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:DelayQueueTest.java


注:本文中的java.util.concurrent.DelayQueue.drainTo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。