当前位置: 首页>>代码示例>>Java>>正文


Java LinkedBlockingDeque.put方法代码示例

本文整理汇总了Java中java.util.concurrent.LinkedBlockingDeque.put方法的典型用法代码示例。如果您正苦于以下问题:Java LinkedBlockingDeque.put方法的具体用法?Java LinkedBlockingDeque.put怎么用?Java LinkedBlockingDeque.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.LinkedBlockingDeque的用法示例。


在下文中一共展示了LinkedBlockingDeque.put方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testDrainToWithActivePut

import java.util.concurrent.LinkedBlockingDeque; //导入方法依赖的package包/类
/**
 * drainTo empties full deque, unblocking a waiting put.
 */
public void testDrainToWithActivePut() throws InterruptedException {
    final LinkedBlockingDeque q = populatedDeque(SIZE);
    Thread t = new Thread(new CheckedRunnable() {
        public void realRun() throws InterruptedException {
            q.put(new Integer(SIZE + 1));
        }});

    t.start();
    ArrayList l = new ArrayList();
    q.drainTo(l);
    assertTrue(l.size() >= SIZE);
    for (int i = 0; i < SIZE; ++i)
        assertEquals(l.get(i), new Integer(i));
    t.join();
    assertTrue(q.size() + l.size() >= SIZE);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:LinkedBlockingDequeTest.java

示例2: testMultiThreadedDecompressorPool

import java.util.concurrent.LinkedBlockingDeque; //导入方法依赖的package包/类
@Test(timeout = 1000)
public void testMultiThreadedDecompressorPool() throws InterruptedException {
  final int iterations = 4;
  ExecutorService threadpool = Executors.newFixedThreadPool(3);
  final LinkedBlockingDeque<Decompressor> queue = new LinkedBlockingDeque<Decompressor>(
      2 * iterations);

  Callable<Boolean> consumer = new Callable<Boolean>() {
    @Override
    public Boolean call() throws Exception {
      Decompressor dc = queue.take();
      CodecPool.returnDecompressor(dc);
      return dc != null;
    }
  };

  Callable<Boolean> producer = new Callable<Boolean>() {
    @Override
    public Boolean call() throws Exception {
      Decompressor c = CodecPool.getDecompressor(codec);
      queue.put(c);
      return c != null;
    }
  };

  for (int i = 0; i < iterations; i++) {
    threadpool.submit(consumer);
    threadpool.submit(producer);
  }

  // wait for completion
  threadpool.shutdown();
  threadpool.awaitTermination(1000, TimeUnit.SECONDS);

  assertEquals(LEASE_COUNT_ERR, 0,
      CodecPool.getLeasedDecompressorsCount(codec));
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:38,代码来源:TestCodecPool.java

示例3: testPut

import java.util.concurrent.LinkedBlockingDeque; //导入方法依赖的package包/类
/**
 * all elements successfully put are contained
 */
public void testPut() throws InterruptedException {
    LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        Integer x = new Integer(i);
        q.put(x);
        assertTrue(q.contains(x));
    }
    assertEquals(0, q.remainingCapacity());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:LinkedBlockingDequeTest.java


注:本文中的java.util.concurrent.LinkedBlockingDeque.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。