本文整理了Java中java.util.concurrent.BlockingQueue.poll()
方法的一些代码示例,展示了BlockingQueue.poll()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BlockingQueue.poll()
方法的具体详情如下:
包路径:java.util.concurrent.BlockingQueue
类名称:BlockingQueue
方法名:poll
[英]Retrieves and removes the head of this queue, waiting up to the specified wait time if necessary for an element to become available.
[中]检索并删除此队列的头,如果需要元素变为可用,则等待指定的等待时间。
代码示例来源: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: stanfordnlp/CoreNLP
@Override
protected Integer getProcessor() {
try {
return (timeout <= 0) ? idleProcessors.take() : idleProcessors.poll(timeout, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
throw new RuntimeInterruptedException(e);
}
}
代码示例来源: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)
return r;
代码示例来源:origin: jersey/jersey
private boolean fetchChunk(final boolean block) throws InterruptedException {
if (eof) {
return false;
}
// Read until no buffers available (poll returned null)
// or until a non-empty buffer or EOF is reached.
do {
if (closed.get()) {
current = EOF;
break;
}
current = (block) ? buffers.take() : buffers.poll();
} while (current != null && current != EOF && !current.hasRemaining());
eof = current == EOF;
return !eof;
}
代码示例来源: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: jersey/jersey
private boolean fetchChunk(final boolean block) throws InterruptedException {
if (eof) {
return false;
}
// Read until no buffers available (poll returned null)
// or until a non-empty buffer or EOF is reached.
do {
if (closed.get()) {
current = EOF;
break;
}
current = (block) ? buffers.take() : buffers.poll();
} while (current != null && current != EOF && !current.hasRemaining());
eof = current == EOF;
return !eof;
}
代码示例来源: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: TooTallNate/Java-WebSocket
@Override
public void run() {
WebSocketImpl ws = null;
try {
while ( true ) {
ByteBuffer buf;
ws = iqueue.take();
buf = ws.inQueue.poll();
assert ( buf != null );
doDecode(ws, buf);
ws = null;
}
} catch ( InterruptedException e ) {
Thread.currentThread().interrupt();
} catch ( RuntimeException e ) {
handleFatal( ws, e );
}
}
代码示例来源: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: netty/netty
Runnable task = null;
try {
task = taskQueue.take();
} catch (InterruptedException e) {
if (delayNanos > 0) {
try {
task = taskQueue.poll(delayNanos, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {
task = taskQueue.poll();
task = taskQueue.poll();
代码示例来源: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: apache/flume
private RandomAccessFile checkOut()
throws IOException, InterruptedException {
RandomAccessFile fileHandle = readFileHandles.poll();
if (fileHandle != null) {
return fileHandle;
}
int remaining = readFileHandles.remainingCapacity();
if (remaining > 0) {
LOG.info("Opening " + file + " for read, remaining number of file " +
"handles available for reads of this file is " + remaining);
return open();
}
return readFileHandles.take();
}
代码示例来源: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: google/guava
Future<T> f = futureQueue.poll();
if (f == null) {
if (ntasks > 0) {
break;
} else if (timed) {
f = futureQueue.poll(timeoutNanos, TimeUnit.NANOSECONDS);
if (f == null) {
throw new TimeoutException();
lastTime = now;
} else {
f = futureQueue.take();
代码示例来源:origin: apache/incubator-gobblin
public void unblock() {
if (!this.queue.isEmpty()) {
this.queue.poll();
}
}
代码示例来源:origin: redisson/redisson
Runnable task = null;
try {
task = taskQueue.take();
} catch (InterruptedException e) {
if (delayNanos > 0) {
try {
task = taskQueue.poll(delayNanos, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {
task = taskQueue.poll();
task = taskQueue.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: apache/incubator-gobblin
/**
* This method returns job specs receive from Kafka. It will block if there are no job specs.
* @return list of (verb, jobspecs) pairs.
*/
@Override
public Future<? extends List<Pair<SpecExecutor.Verb, Spec>>> changedSpecs() {
List<Pair<SpecExecutor.Verb, Spec>> changesSpecs = new ArrayList<>();
try {
Pair<SpecExecutor.Verb, Spec> specPair = _jobSpecQueue.take();
_metrics.jobSpecDeqCount.incrementAndGet();
do {
changesSpecs.add(specPair);
// if there are more elements then pass them along in this call
specPair = _jobSpecQueue.poll();
} while (specPair != null);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return new CompletedFuture(changesSpecs, null);
}
代码示例来源: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: robolectric/robolectric
/**
* May block the current thread and wait until {@link BluetoothDevice} is offered via
* {@link #deviceConnected(BluetoothDevice)} method or timeout occurred.
*
* @return socket of the connected bluetooth device
* @throws IOException if socket has been closed, thread interrupted while waiting or timeout has
* occurred.
*/
@Implementation
protected BluetoothSocket accept(int timeout) throws IOException {
if (closed) {
throw new IOException("Socket closed");
}
BluetoothSocket socket;
try {
socket = timeout == -1
? sockets.take() : sockets.poll(timeout, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
throw new IOException(e);
}
if (socket == null) {
throw new IOException("Timeout occurred");
}
socket.connect();
return socket;
}
内容来源于网络,如有侵权,请联系作者删除!