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


Java ConcurrentLinkedQueue.isEmpty方法代碼示例

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


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

示例1: simpleAnalyze

import java.util.concurrent.ConcurrentLinkedQueue; //導入方法依賴的package包/類
public AnalysisResults simpleAnalyze(String text) {
    final AnalyzeOptions parameters = new AnalyzeOptions.Builder()
            .text(text)
            .language("en")
            .features(features)
            .build();
    final ConcurrentLinkedQueue<AnalysisResults> queue = new ConcurrentLinkedQueue<>();
    new Thread(new Runnable() {
        @Override
        public void run() {
            queue.add(service
                    .analyze(parameters)
                    .execute());
        }
    }).start();
    while (queue.isEmpty())
        try {
            Thread.sleep(100, 0);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    //System.out.println(response);
    return queue.peek();
}
 
開發者ID:zackszhu,項目名稱:hack_sjtu_2017,代碼行數:26,代碼來源:NlpClient.java

示例2: processUpdate

import java.util.concurrent.ConcurrentLinkedQueue; //導入方法依賴的package包/類
/**
 * Process all incoming entity update requests.
 */
private void processUpdate() {
    // TODO: Remove memory leak for updates that belong to non-existing entities
    for(Map.Entry<Integer, Entity> e : entities.entrySet()) {
        Entity entity = e.getValue();
        ConcurrentLinkedQueue<EntityUpdate> updates = updateMap.get(entity.getId());

        while(!updates.isEmpty()) {
            updates.poll().update(entity);
        }
    }
}
 
開發者ID:INAETICS,項目名稱:Drones-Simulator,代碼行數:15,代碼來源:EntityManager.java

示例3: clean

import java.util.concurrent.ConcurrentLinkedQueue; //導入方法依賴的package包/類
public void clean() {
    // the lock protects removal from a concurrent put which could otherwise mutate the
    // queue after it has been removed from the map
    synchronized (unsent) {
        Iterator<ConcurrentLinkedQueue<ClientRequest>> iterator = unsent.values().iterator();
        while (iterator.hasNext()) {
            ConcurrentLinkedQueue<ClientRequest> requests = iterator.next();
            if (requests.isEmpty())
                iterator.remove();
        }
    }
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:13,代碼來源:ConsumerNetworkClient.java

示例4: hasRequests

import java.util.concurrent.ConcurrentLinkedQueue; //導入方法依賴的package包/類
public boolean hasRequests(Node node) {
    ConcurrentLinkedQueue<ClientRequest> requests = unsent.get(node);
    return requests != null && !requests.isEmpty();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:5,代碼來源:ConsumerNetworkClient.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.isEmpty方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。