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