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


Java SynchronousQueue.drainTo方法代碼示例

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


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

示例1: testDrainToWithActivePut

import java.util.concurrent.SynchronousQueue; //導入方法依賴的package包/類
public void testDrainToWithActivePut(boolean fair) {
    final SynchronousQueue q = new SynchronousQueue(fair);
    Thread t = newStartedThread(new CheckedRunnable() {
        public void realRun() throws InterruptedException {
            q.put(one);
        }});

    ArrayList l = new ArrayList();
    long startTime = System.nanoTime();
    while (l.isEmpty()) {
        q.drainTo(l);
        if (millisElapsedSince(startTime) > LONG_DELAY_MS)
            fail("timed out");
        Thread.yield();
    }
    assertEquals(1, l.size());
    assertSame(one, l.get(0));
    awaitTermination(t);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:SynchronousQueueTest.java

示例2: testDrainToN

import java.util.concurrent.SynchronousQueue; //導入方法依賴的package包/類
/**
 * drainTo(c, n) empties up to n elements of queue into c
 */
public void testDrainToN() throws InterruptedException {
    final SynchronousQueue q = new SynchronousQueue();
    Thread t1 = newStartedThread(new CheckedRunnable() {
        public void realRun() throws InterruptedException {
            q.put(one);
        }});

    Thread t2 = newStartedThread(new CheckedRunnable() {
        public void realRun() throws InterruptedException {
            q.put(two);
        }});

    ArrayList l = new ArrayList();
    int drained;
    while ((drained = q.drainTo(l, 1)) == 0) Thread.yield();
    assertEquals(1, drained);
    assertEquals(1, l.size());
    while ((drained = q.drainTo(l, 1)) == 0) Thread.yield();
    assertEquals(1, drained);
    assertEquals(2, l.size());
    assertTrue(l.contains(one));
    assertTrue(l.contains(two));
    awaitTermination(t1);
    awaitTermination(t2);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:29,代碼來源:SynchronousQueueTest.java

示例3: testDrainTo

import java.util.concurrent.SynchronousQueue; //導入方法依賴的package包/類
public void testDrainTo(boolean fair) {
    final SynchronousQueue q = new SynchronousQueue(fair);
    ArrayList l = new ArrayList();
    q.drainTo(l);
    assertEquals(0, q.size());
    assertEquals(0, l.size());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:SynchronousQueueTest.java


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