当前位置: 首页>>代码示例>>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;未经允许,请勿转载。