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

x33g5p2x  于2022-01-23 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(205)

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

LinkedBlockingDeque.poll介绍

暂无

代码示例

代码示例来源:origin: zendesk/maxwell

protected BinlogConnectorEvent pollEvent() throws InterruptedException {
  return queue.poll(100, TimeUnit.MILLISECONDS);
}

代码示例来源:origin: prestodb/presto

@Nullable
public SerializedPage pollPage()
{
  checkState(!Thread.holdsLock(this), "Can not get next page while holding a lock on this");
  throwIfFailed();
  if (closed.get()) {
    return null;
  }
  SerializedPage page = pageBuffer.poll();
  return postProcessPage(page);
}

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

@Override
  public PooledObject allocate() {
    T obj = pool.poll();
    if(obj == null) {
      obj = supplier.get();
    }
    final T finObj = obj;
    return new PooledObject() {

      private volatile boolean closed = false;

      @Override
      public T getObject() {
        if (closed) {
          throw UndertowMessages.MESSAGES.objectIsClosed();
        }
        return finObj;
      }

      @Override
      public void close() {
        closed = true;
        recycler.accept(finObj);
        if(!pool.offer(finObj)) {
          consumer.accept(finObj);
        }
      }
    };
  }
}

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

public K poll() {
  synchronized (_lock) {
    Iterator<LinkedBlockingDeque<K>> itr = _buckets.descendingIterator();
    while (itr.hasNext()) {
      LinkedBlockingDeque<K> bucket = itr.next();
      K entry = bucket.poll();
      if (entry != null) {
        return entry;
      }
    }
    return null;
  }
}

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

@Override
  public void run() {
    while (!taskRunQueue.isEmpty()) {
      taskRunQueue.poll().run();
    }
  }
};

代码示例来源:origin: google/ExoPlayer

/**
 * Asserts that the source notifies its listener of a single timeline change. If the source has
 * not yet notified its listener, it has up to the timeout passed to the constructor to do so.
 *
 * @return The new {@link Timeline}.
 */
public Timeline assertTimelineChangeBlocking() {
 try {
  timeline = timelines.poll(TIMEOUT_MS, TimeUnit.MILLISECONDS);
  assertThat(timeline).isNotNull(); // Null indicates the poll timed out.
  assertNoTimelineChange();
  return timeline;
 } catch (InterruptedException e) {
  // Should never happen.
  throw new RuntimeException(e);
 }
}

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

/**
 * Check if any {@link WorkUnit} is available. The producer is {@link SingleWorkUnitGeneratorService}
 * @return true when a new {@link WorkUnit} is available
 *         false when {@link CompactionWorkUnitIterator#isDone} is invoked
 */
public boolean hasNext () {
 try {
  while (true) {
   if (last != null) return true;
   if (this.isDone.get() && this.workUnits.isEmpty()) return false;
   this.last = this.workUnits.poll(1, TimeUnit.SECONDS);
  }
 } catch (InterruptedException e) {
  log.error(e.toString());
  return false;
 }
}

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

@Override
public boolean hasNext() {
 initialize();
 if (_next != null) {
  return true;
 }
 //if _next doesn't exist, try polling the next one.
 try {
  _next = _dataSink.poll(_pollBlockingTime, TimeUnit.SECONDS);
  while (_next == null) {
   if (_producerThread.isAlive()) {
    log.info(String.format("Producer job not done yet. Will re-poll for %s second(s)...", _pollBlockingTime));
    _next = _dataSink.poll(_pollBlockingTime, TimeUnit.SECONDS);
    continue;
   }
   synchronized (lock) {
    if (exceptionInProducerThread != null) {
     throw new RuntimeException(
       String.format("Found exception in producer thread %s", _producerThread.getName()),
       exceptionInProducerThread);
    }
   }
   log.info("Producer job done. No more data in the queue.");
   return false;
  }
  return true;
 } catch (InterruptedException e) {
  throw new RuntimeException(e);
 }
}

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

public void addUpdatedDom2Queue(String namespaceId, String domName, String serverIP, String checksum) {
  lock.lock();
  try {
    toBeUpdatedDomsQueue.offer(new DomainKey(namespaceId, domName, serverIP, checksum), 5, TimeUnit.MILLISECONDS);
  } catch (Exception e) {
    toBeUpdatedDomsQueue.poll();
    toBeUpdatedDomsQueue.add(new DomainKey(namespaceId, domName, serverIP, checksum));
    Loggers.SRV_LOG.error("[DOMAIN-STATUS] Failed to add domain to be updatd to queue.", e);
  } finally {
    lock.unlock();
  }
}

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

@Override
public ByteBuf readChunk(ByteBufAllocator allocator) throws Exception {
  if (!open) {
    return null;
  }
  ByteBuffer top = queue.poll(READ_TIMEOUT, TimeUnit.MILLISECONDS);
  if (top == null) {
    // returning empty buffer instead of null causes flush (which is needed for BroadcasterTest and others..).
    return Unpooled.EMPTY_BUFFER;
  }
  if (top == VOID) {
    open = false;
    return null;
  }
  int topRemaining = top.remaining();
  ByteBuf buffer = allocator.buffer(topRemaining);
  buffer.setBytes(0, top);
  buffer.setIndex(0, topRemaining);
  if (top.remaining() > 0) {
    queue.addFirst(top);
  }
  offset += topRemaining;
  return buffer;
}

代码示例来源:origin: Qihoo360/XLearning

this.containersCpuMetrics.get(containerId).get(str).add(map.get(str));
} else {
 this.containersCpuMetrics.get(containerId).get(str).poll();
 this.containersCpuMetrics.get(containerId).get(str).add(map.get(str));

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

head = outgoingQueue.poll(waitTimeOut, TimeUnit.MILLISECONDS);

代码示例来源:origin: google/ExoPlayer

/**
 * Asserts that the source notifies its listener of a single timeline change. If the source has
 * not yet notified its listener, it has up to the timeout passed to the constructor to do so.
 *
 * @return The new {@link Timeline}.
 */
public Timeline assertTimelineChangeBlocking() {
 try {
  timeline = timelines.poll(TIMEOUT_MS, TimeUnit.MILLISECONDS);
  assertThat(timeline).isNotNull(); // Null indicates the poll timed out.
  assertNoTimelineChange();
  return timeline;
 } catch (InterruptedException e) {
  // Should never happen.
  throw new RuntimeException(e);
 }
}

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

@Override
protected Event doTake() throws InterruptedException {
 channelCounter.incrementEventTakeAttemptCount();
 if (takeList.remainingCapacity() == 0) {
  throw new ChannelException("Take list for MemoryTransaction, capacity " +
    takeList.size() + " full, consider committing more frequently, " +
    "increasing capacity, or increasing thread count");
 }
 if (!queueStored.tryAcquire(keepAlive, TimeUnit.SECONDS)) {
  return null;
 }
 Event event;
 synchronized (queueLock) {
  event = queue.poll();
 }
 Preconditions.checkNotNull(event, "Queue.poll returned NULL despite semaphore " +
   "signalling existence of entry");
 takeList.put(event);
 int eventByteSize = (int) Math.ceil(estimateEventSize(event) / byteCapacitySlotSize);
 takeByteCounter += eventByteSize;
 return event;
}

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

return true;
} else if (current == Type.DIGEST) {
  DigestImpl current = digestList.poll();
  if (current == null) {
    return false;

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

void close() {
 logger.debug( "[#{}] Query listener closing.", instanceId );
 closed = true;
 if ( stopThrottlingIfSo() ) {
  logger.debug( "[#{}] Throttling stopped at close() (at queue size {}).",
         instanceId, batchQueue.size() );
 }
 while (!batchQueue.isEmpty()) {
  // Don't bother with query timeout, we're closing the cursor
  QueryDataBatch qdb = batchQueue.poll();
  if (qdb != null && qdb.getData() != null) {
   qdb.getData().release();
  }
 }
 // Close may be called before the first result is received and therefore
 // when the main thread is blocked waiting for the result.  In that case
 // we want to unblock the main thread.
 firstMessageReceived.countDown(); // TODO:  Why not call releaseIfFirst as used elsewhere?
 completed = true;
}

代码示例来源:origin: loklak/loklak_server

int maxBulkSize = 200;
List<DAO.MessageWrapper> bulk = new ArrayList<>();
pollloop: while ((mw = messageQueue.poll()) != null) {
  if (DAO.messages.existsCache(mw.t.getPostId())) {
     doubleMessageCounter.incrementAndGet();

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

return null;
} else {
 QueryDataBatch qdb = batchQueue.poll(50, TimeUnit.MILLISECONDS);
 if (qdb != null) {
  lastDequeuedBatchNumber++;

代码示例来源:origin: camunda/camunda-bpm-platform

@Override
  public void run() {
    while (run) {
      try {
        LogEntry entry = queue.poll(LOGGER_SLEEP_TIME, TimeUnit.MILLISECONDS);
        if (entry!=null) entry.flush();
      }catch (InterruptedException x) {
        Thread.interrupted();
      }catch (Exception x) {
        x.printStackTrace();
      }
    }//while
  }
}

代码示例来源:origin: hector-client/hector

void add(double i) {
 if (intervalupdates.intValue() >= UPDATES_PER_INTERVAL)
  return;
 if (!latencies.offer(i)) {
  latencies.poll();
  latencies.offer(i);
 }
 intervalupdates.getAndIncrement();
}

相关文章

微信公众号

最新文章

更多