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


Java ConcurrentLinkedQueue.addAll方法代碼示例

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


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

示例1: testAddAll1

import java.util.concurrent.ConcurrentLinkedQueue; //導入方法依賴的package包/類
/**
 * addAll(null) throws NullPointerException
 */
public void testAddAll1() {
    ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
    try {
        q.addAll(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:ConcurrentLinkedQueueTest.java

示例2: testAddAllSelf

import java.util.concurrent.ConcurrentLinkedQueue; //導入方法依賴的package包/類
/**
 * addAll(this) throws IllegalArgumentException
 */
public void testAddAllSelf() {
    ConcurrentLinkedQueue q = populatedQueue(SIZE);
    try {
        q.addAll(q);
        shouldThrow();
    } catch (IllegalArgumentException success) {}
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:ConcurrentLinkedQueueTest.java

示例3: testAddAll2

import java.util.concurrent.ConcurrentLinkedQueue; //導入方法依賴的package包/類
/**
 * addAll of a collection with null elements throws NullPointerException
 */
public void testAddAll2() {
    ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
    try {
        q.addAll(Arrays.asList(new Integer[SIZE]));
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:ConcurrentLinkedQueueTest.java

示例4: testAddAll3

import java.util.concurrent.ConcurrentLinkedQueue; //導入方法依賴的package包/類
/**
 * addAll of a collection with any null elements throws NPE after
 * possibly adding some elements
 */
public void testAddAll3() {
    ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
    Integer[] ints = new Integer[SIZE];
    for (int i = 0; i < SIZE - 1; ++i)
        ints[i] = new Integer(i);
    try {
        q.addAll(Arrays.asList(ints));
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:ConcurrentLinkedQueueTest.java

示例5: testCacheMultiThreaded

import java.util.concurrent.ConcurrentLinkedQueue; //導入方法依賴的package包/類
public static void testCacheMultiThreaded(final BlockCache toBeTested,
    final int blockSize, final int numThreads, final int numQueries,
    final double passingScore) throws Exception {

  Configuration conf = new Configuration();
  MultithreadedTestUtil.TestContext ctx = new MultithreadedTestUtil.TestContext(
      conf);

  final AtomicInteger totalQueries = new AtomicInteger();
  final ConcurrentLinkedQueue<HFileBlockPair> blocksToTest = new ConcurrentLinkedQueue<HFileBlockPair>();
  final AtomicInteger hits = new AtomicInteger();
  final AtomicInteger miss = new AtomicInteger();

  HFileBlockPair[] blocks = generateHFileBlocks(numQueries, blockSize);
  blocksToTest.addAll(Arrays.asList(blocks));

  for (int i = 0; i < numThreads; i++) {
    TestThread t = new MultithreadedTestUtil.RepeatingTestThread(ctx) {
      @Override
      public void doAnAction() throws Exception {
        if (!blocksToTest.isEmpty()) {
          HFileBlockPair ourBlock = blocksToTest.poll();
          // if we run out of blocks to test, then we should stop the tests.
          if (ourBlock == null) {
            ctx.setStopFlag(true);
            return;
          }
          toBeTested.cacheBlock(ourBlock.blockName, ourBlock.block);
          Cacheable retrievedBlock = toBeTested.getBlock(ourBlock.blockName,
              false, false, true);
          if (retrievedBlock != null) {
            assertEquals(ourBlock.block, retrievedBlock);
            toBeTested.evictBlock(ourBlock.blockName);
            hits.incrementAndGet();
            assertNull(toBeTested.getBlock(ourBlock.blockName, false, false, true));
          } else {
            miss.incrementAndGet();
          }
          totalQueries.incrementAndGet();
        }
      }
    };
    t.setDaemon(true);
    ctx.addThread(t);
  }
  ctx.startThreads();
  while (!blocksToTest.isEmpty() && ctx.shouldRun()) {
    Thread.sleep(10);
  }
  ctx.stop();
  if (hits.get() / ((double) hits.get() + (double) miss.get()) < passingScore) {
    fail("Too many nulls returned. Hits: " + hits.get() + " Misses: "
        + miss.get());
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:56,代碼來源:CacheTestUtils.java


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