java.util.concurrent.BlockingQueue.isEmpty()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(216)

本文整理了Java中java.util.concurrent.BlockingQueue.isEmpty()方法的一些代码示例,展示了BlockingQueue.isEmpty()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BlockingQueue.isEmpty()方法的具体详情如下:
包路径:java.util.concurrent.BlockingQueue
类名称:BlockingQueue
方法名:isEmpty

BlockingQueue.isEmpty介绍

暂无

代码示例

代码示例来源:origin: apache/incubator-druid

@Override
public void run()
{
 while (!eventQueue.isEmpty() && !scheduler.isShutdown()) {
  OpentsdbEvent event = eventQueue.poll();
  events.add(event);
  if (events.size() >= flushThreshold) {
   sendEvents();
  }
 }
}

代码示例来源:origin: lettuce-io/lettuce-core

private List<RedisCommand<Object, Object, Object>> prepareForceFlush() {
  List<RedisCommand<Object, Object, Object>> batch = new ArrayList<>(Math.max(batchSize, 10));
  do {
    RedisCommand<Object, Object, Object> poll = queue.poll();
    assert poll != null;
    batch.add(poll);
  } while (!queue.isEmpty());
  return batch;
}

代码示例来源:origin: graphhopper/graphhopper

private ReaderElement getNextPBF() {
    ReaderElement next = null;
    while (next == null) {
      if (!hasIncomingData && itemQueue.isEmpty()) {
        // we are done, stop polling
        eof = true;
        break;
      }

      try {
        // we cannot use "itemQueue.take()" as it blocks and hasIncomingData can change
        next = itemQueue.poll(10, TimeUnit.MILLISECONDS);
      } catch (InterruptedException ex) {
        eof = true;
        break;
      }
    }
    return next;
  }
}

代码示例来源:origin: osmandapp/Osmand

public void refuseAllPreviousRequests() {
    // That's very strange because exception in impl of queue (possibly wrong impl)
//        threadPoolExecutor.getQueue().clear();
    while (!threadPoolExecutor.getQueue().isEmpty()) {
      threadPoolExecutor.getQueue().poll();
    }
    pendingToDownload.clear();
  }

代码示例来源:origin: lettuce-io/lettuce-core

private List<RedisCommand<Object, Object, Object>> prepareDefaultFlush(int consume) {

    List<RedisCommand<Object, Object, Object>> batch = new ArrayList<>(Math.max(consume, 10));

    while ((batch.size() < consume || consume == -1) && !queue.isEmpty()) {

      RedisCommand<Object, Object, Object> poll = queue.poll();

      assert poll != null;
      batch.add(poll);
    }

    return batch;
  }
}

代码示例来源:origin: alibaba/fescar

@Override
  public void run() {
    while (true) {
      if (messageStrings.size() > 0) {
        StringBuilder builder = new StringBuilder();
        while (!messageStrings.isEmpty()) {
          builder.append(messageStrings.poll()).append(BATCH_LOG_SPLIT);
        }
        if (LOGGER.isInfoEnabled()) {
          LOGGER.info(builder.toString());
        }
      }
      try {
        Thread.sleep(IDLE_CHECK_MILLS);
      } catch (InterruptedException exx) {
        LOGGER.error(exx.getMessage());
      }
    }
  }
}

代码示例来源:origin: apache/incubator-gobblin

public void unblock() {
 if (!this.queue.isEmpty()) {
  this.queue.poll();
 }
}

代码示例来源:origin: alibaba/jstorm

@Override
public void removeSupervisors(int number) throws TException {
  if (jstormMaster.jstormMasterContext.supervisorContainers.isEmpty())
    return;
  for (int i = 0; i < number; i++) {
    Container container = jstormMaster.jstormMasterContext.supervisorContainers.poll();
    if (container != null) {
      amRMClient.releaseAssignedContainer(container.getId());
      LOG.info("release supervisor's " + String.valueOf(number) + " container, id: " + container.getId().toString());
    }
  }
}

代码示例来源:origin: alibaba/jstorm

@Override
public void stopNimbus() throws TException {
  if (jstormMasterContext.nimbusContainers.isEmpty())
    return;
  int nimbusCount = jstormMasterContext.nimbusContainers.size();
  for (int i = 0; i < nimbusCount; i++) {
    Container container = jstormMasterContext.nimbusContainers.poll();
    if (container != null) {
      amRMClient.releaseAssignedContainer(container.getId());
      LOG.info("release nimbus container, id: " + container.getId().toString());
    }
  }
}

代码示例来源:origin: alibaba/jstorm

@Override
public void stopSupervisors() throws TException {
  if (jstormMaster.jstormMasterContext.supervisorContainers.isEmpty())
    return;
  int supervisorCount = jstormMaster.jstormMasterContext.supervisorContainers.size();
  for (int i = 0; i < supervisorCount; i++) {
    Container container = jstormMaster.jstormMasterContext.supervisorContainers.poll();
    if (container != null) {
      amRMClient.releaseAssignedContainer(container.getId());
      LOG.info("release all supervisor container, id: " + container.getId().toString());
    }
  }
}

代码示例来源:origin: konsoletyper/teavm

public void init() {
  latch = new CountDownLatch(numThreads);
  for (int i = 0; i < numThreads; ++i) {
    new Thread(() -> {
      strategy.beforeThread();
      while (!stopped || !taskQueue.isEmpty()) {
        Runnable task;
        try {
          task = taskQueue.poll(100, TimeUnit.MILLISECONDS);
        } catch (InterruptedException e) {
          break;
        }
        if (task != null) {
          task.run();
        }
      }
      strategy.afterThread();
      latch.countDown();
    }).start();
  }
}

代码示例来源:origin: alibaba/jstorm

@Override
public void removeNimbus(int number) throws TException {
  if (jstormMasterContext.nimbusContainers.isEmpty())
    return;
  for (int i = 0; i < number; i++) {
    Container container = jstormMasterContext.nimbusContainers.poll();
    if (container != null) {
      amRMClient.releaseAssignedContainer(container.getId());
      LOG.info("release nimbus container, id: " + container.getId().toString());
    }
  }
}

代码示例来源:origin: apache/ignite

/**
 * Cancel thread execution and completes all notification futures.
 */
@Override public synchronized void cancel() {
  super.cancel();
  while (!queue.isEmpty()) {
    T2<GridFutureAdapter, Runnable> notification = queue.poll();
    if (notification != null)
      notification.get1().onDone();
  }
}

代码示例来源:origin: apache/nifi

@Override
public final void process() throws IOException {
  if (isConsumerFinished()) {
    return;
  }
  if (streamEnded.get() && filledBuffers.isEmpty()) {
    consumerEnded.set(true);
    onConsumerDone();
    return;
  }
  final ByteBuffer buffer = filledBuffers.poll();
  if (buffer != null) {
    final int bytesToProcess = buffer.remaining();
    try {
      processBuffer(buffer);
    } finally {
      buffer.clear();
      bufferPool.returnBuffer(buffer, bytesToProcess);
    }
  }
}

代码示例来源:origin: apache/nifi

@Override
  public Object call() throws IOException {
    while (!eventQueue.isEmpty() || !finishedAdding.get()) {
      try {
        final Tuple<StandardProvenanceEventRecord, Integer> tuple;
        try {
          tuple = eventQueue.poll(10, TimeUnit.MILLISECONDS);
        } catch (final InterruptedException ie) {
          Thread.currentThread().interrupt();
          continue;
        }
        if (tuple == null) {
          continue;
        }
        indexingAction.index(tuple.getKey(), indexWriter.getIndexWriter(), tuple.getValue());
      } catch (final Throwable t) {
        logger.error("Failed to index Provenance Event for " + writerFile + " to " + indexingDirectory, t);
        if (indexingFailureCount.incrementAndGet() >= MAX_INDEXING_FAILURE_COUNT) {
          return null;
        }
      }
    }
    return null;
  }
};

代码示例来源:origin: alibaba/fescar

for (String address : basketMap.keySet()) {
  BlockingQueue<RpcMessage> basket = basketMap.get(address);
  if (basket.isEmpty()) { continue; }
  while (!basket.isEmpty()) {
    RpcMessage msg = basket.poll();
    mergeMessage.msgs.add((AbstractMessage)msg.getBody());
    mergeMessage.msgIds.add(msg.getId());

代码示例来源:origin: apache/hive

ExecutorService consumer = Executors.newFixedThreadPool(nThreads, namingThreadFactory);
while (!producer.isTerminated() || !queue.isEmpty()) {
 Partition partition = queue.poll(1, TimeUnit.SECONDS);
 if (partition == null) {
  continue;

代码示例来源:origin: igniterealtime/Smack

if (this.readTimeout == 0) {
  while (data == null) {
    if (isClosed && this.dataQueue.isEmpty()) {
      return false;
    data = this.dataQueue.poll(1000, TimeUnit.MILLISECONDS);
  data = this.dataQueue.poll(this.readTimeout, TimeUnit.MILLISECONDS);
  if (data == null) {
    throw new SocketTimeoutException();

代码示例来源:origin: neo4j/neo4j

tellNextThreadToInitialize();
while ( !done || !recordsQ.isEmpty() )
    record = recordsQ.poll( 10, TimeUnit.MILLISECONDS );
    if ( record != null )

代码示例来源:origin: robovm/robovm

if (rs >= SHUTDOWN && (rs >= STOP || workQueue.isEmpty())) {
  decrementWorkerCount();
  return null;
  && (wc > 1 || workQueue.isEmpty())) {
  if (compareAndDecrementWorkerCount(c))
    return null;
    workQueue.poll(keepAliveTime, TimeUnit.NANOSECONDS) :
    workQueue.take();
  if (r != null)

相关文章