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


Java LinkedTransferQueue.isEmpty方法代碼示例

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


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

示例1: testTransfer2

import java.util.concurrent.LinkedTransferQueue; //導入方法依賴的package包/類
/**
 * transfer waits until a poll occurs. The transfered element
 * is returned by the associated poll.
 */
public void testTransfer2() throws InterruptedException {
    final LinkedTransferQueue<Integer> q = new LinkedTransferQueue<>();
    final CountDownLatch threadStarted = new CountDownLatch(1);

    Thread t = newStartedThread(new CheckedRunnable() {
        public void realRun() throws InterruptedException {
            threadStarted.countDown();
            q.transfer(five);
            checkEmpty(q);
        }});

    threadStarted.await();
    Callable<Boolean> oneElement
        = new Callable<Boolean>() { public Boolean call() {
            return !q.isEmpty() && q.size() == 1; }};
    waitForThreadToEnterWaitState(t, oneElement);

    assertSame(five, q.poll());
    checkEmpty(q);
    awaitTermination(t);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:LinkedTransferQueueTest.java

示例2: testTransfer4

import java.util.concurrent.LinkedTransferQueue; //導入方法依賴的package包/類
/**
 * transfer waits until a poll occurs, at which point the polling
 * thread returns the element
 */
public void testTransfer4() throws InterruptedException {
    final LinkedTransferQueue q = new LinkedTransferQueue();

    Thread t = newStartedThread(new CheckedRunnable() {
        public void realRun() throws InterruptedException {
            q.transfer(four);
            assertFalse(q.contains(four));
            assertSame(three, q.poll());
        }});

    while (q.isEmpty())
        Thread.yield();
    assertFalse(q.isEmpty());
    assertEquals(1, q.size());
    assertTrue(q.offer(three));
    assertSame(four, q.poll());
    awaitTermination(t);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:LinkedTransferQueueTest.java

示例3: testTransfer5

import java.util.concurrent.LinkedTransferQueue; //導入方法依賴的package包/類
/**
 * transfer waits until a take occurs. The transfered element
 * is returned by the associated take.
 */
public void testTransfer5() throws InterruptedException {
    final LinkedTransferQueue<Integer> q = new LinkedTransferQueue<>();

    Thread t = newStartedThread(new CheckedRunnable() {
        public void realRun() throws InterruptedException {
            q.transfer(four);
            checkEmpty(q);
        }});

    while (q.isEmpty())
        Thread.yield();
    assertFalse(q.isEmpty());
    assertEquals(1, q.size());
    assertSame(four, q.take());
    checkEmpty(q);
    awaitTermination(t);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:LinkedTransferQueueTest.java


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