本文整理了Java中java.util.concurrent.BlockingQueue.iterator()
方法的一些代码示例,展示了BlockingQueue.iterator()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BlockingQueue.iterator()
方法的具体详情如下:
包路径:java.util.concurrent.BlockingQueue
类名称:BlockingQueue
方法名:iterator
暂无
代码示例来源:origin: apache/hbase
@Override
public Iterator<Runnable> iterator() {
return new Iterator<Runnable>() {
final Iterator<Call> underlyingIterator = underlyingQueue.iterator();
@Override
public Runnable next() {
return underlyingIterator.next();
}
@Override
public boolean hasNext() {
return underlyingIterator.hasNext();
}
@Override
public void remove() {
underlyingIterator.remove();
}
};
}
代码示例来源:origin: org.apache.hadoop/hadoop-common
@Override
public Iterator<E> iterator() {
return takeRef.get().iterator();
}
代码示例来源:origin: apache/hbase
public String dumpQueue() {
StringBuilder queueList = new StringBuilder();
queueList.append("Flush Queue Queue dump:\n");
queueList.append(" Flush Queue:\n");
java.util.Iterator<FlushQueueEntry> it = flushQueue.iterator();
while(it.hasNext()){
queueList.append(" "+it.next().toString());
queueList.append("\n");
}
return queueList.toString();
}
代码示例来源:origin: apache/hbase
public String dumpQueue() {
StringBuilder queueLists = new StringBuilder();
queueLists.append("Compaction/Split Queue dump:\n");
queueLists.append(" LargeCompation Queue:\n");
BlockingQueue<Runnable> lq = longCompactions.getQueue();
Iterator<Runnable> it = lq.iterator();
while (it.hasNext()) {
queueLists.append(" " + it.next().toString());
queueLists.append("\n");
}
if (shortCompactions != null) {
queueLists.append("\n");
queueLists.append(" SmallCompation Queue:\n");
lq = shortCompactions.getQueue();
it = lq.iterator();
while (it.hasNext()) {
queueLists.append(" " + it.next().toString());
queueLists.append("\n");
}
}
queueLists.append("\n");
queueLists.append(" Split Queue:\n");
lq = splits.getQueue();
it = lq.iterator();
while (it.hasNext()) {
queueLists.append(" " + it.next().toString());
queueLists.append("\n");
}
return queueLists.toString();
}
代码示例来源:origin: ehcache/ehcache3
private List<Runnable> abortTasks() {
List<Runnable> abortedTasks = new ArrayList<>();
for (Iterator<Runnable> it = scheduler.getQueue().iterator(); it.hasNext(); ) {
Runnable job = it.next();
if (job instanceof OutOfBandRsf) {
OutOfBandRsf<?> oobJob = (OutOfBandRsf<?>) job;
if (oobJob.getExecutor() == worker) {
abortedTasks.add(job);
it.remove();
}
}
}
abortedTasks.addAll(worker.shutdownNow());
return abortedTasks;
}
代码示例来源:origin: robovm/robovm
/**
* Tries to remove from the work queue all {@link Future}
* tasks that have been cancelled. This method can be useful as a
* storage reclamation operation, that has no other impact on
* functionality. Cancelled tasks are never executed, but may
* accumulate in work queues until worker threads can actively
* remove them. Invoking this method instead tries to remove them now.
* However, this method may fail to remove tasks in
* the presence of interference by other threads.
*/
public void purge() {
final BlockingQueue<Runnable> q = workQueue;
try {
Iterator<Runnable> it = q.iterator();
while (it.hasNext()) {
Runnable r = it.next();
if (r instanceof Future<?> && ((Future<?>)r).isCancelled())
it.remove();
}
} catch (ConcurrentModificationException fallThrough) {
// Take slow path if we encounter interference during traversal.
// Make copy for traversal and call remove for cancelled entries.
// The slow path is more likely to be O(N*N).
for (Object r : q.toArray())
if (r instanceof Future<?> && ((Future<?>)r).isCancelled())
q.remove(r);
}
tryTerminate(); // In case SHUTDOWN and now empty
}
代码示例来源:origin: ehcache/ehcache3
private long getMaxDelay() {
long maxDelay = 0;
for (Iterator<Runnable> it = scheduler.getQueue().iterator(); it.hasNext(); ) {
Runnable job = it.next();
if (job instanceof OutOfBandRsf) {
OutOfBandRsf<?> oobJob = (OutOfBandRsf<?>) job;
if (oobJob.getExecutor() == worker) {
if (oobJob.isPeriodic()) {
oobJob.cancel(false);
it.remove();
} else {
maxDelay = Math.max(maxDelay, oobJob.getDelay(NANOSECONDS));
}
}
}
}
return maxDelay;
}
代码示例来源:origin: internetarchive/heritrix3
/** Compact report of all nonempty queues (one queue per line)
*
* @param writer
*/
public void allNonemptyReportTo(PrintWriter writer) {
ArrayList<WorkQueue> inProcessQueuesCopy;
synchronized(this.inProcessQueues) {
// grab a copy that will be stable against mods for report duration
Collection<WorkQueue> inProcess = this.inProcessQueues;
inProcessQueuesCopy = new ArrayList<WorkQueue>(inProcess);
}
writer.print("\n -----===== IN-PROCESS QUEUES =====-----\n");
queueSingleLinesTo(writer, inProcessQueuesCopy.iterator());
writer.print("\n -----===== READY QUEUES =====-----\n");
queueSingleLinesTo(writer, this.readyClassQueues.iterator());
writer.print("\n -----===== SNOOZED QUEUES =====-----\n");
queueSingleLinesTo(writer, this.snoozedClassQueues.iterator());
queueSingleLinesTo(writer, this.snoozedOverflow.values().iterator());
writer.print("\n -----===== INACTIVE QUEUES =====-----\n");
for(Queue<String> inactiveQueues : getInactiveQueuesByPrecedence().values()) {
queueSingleLinesTo(writer, inactiveQueues.iterator());
}
writer.print("\n -----===== RETIRED QUEUES =====-----\n");
queueSingleLinesTo(writer, getRetiredQueues().iterator());
}
代码示例来源:origin: apache/geode
private boolean destroyFromTempQueue(PartitionedRegion qPR, int bId, Object key) {
boolean isDestroyed = false;
Set queues = qPR.getParallelGatewaySender().getQueues();
if (queues != null) {
ConcurrentParallelGatewaySenderQueue prq =
(ConcurrentParallelGatewaySenderQueue) queues.toArray()[0];
BlockingQueue<GatewaySenderEventImpl> tempQueue = prq.getBucketTmpQueue(bId);
if (tempQueue != null) {
Iterator<GatewaySenderEventImpl> itr = tempQueue.iterator();
while (itr.hasNext()) {
GatewaySenderEventImpl eventForFilter = itr.next();
// fix for #48082
afterAckForSecondary_EventInTempQueue(qPR.getParallelGatewaySender(), eventForFilter);
if (eventForFilter.getShadowKey().equals(key)) {
itr.remove();
eventForFilter.release(); // GEODE-1282
isDestroyed = true;
}
}
}
}
return isDestroyed;
}
代码示例来源:origin: internetarchive/heritrix3
appendQueueReports(writer, "READY", this.readyClassQueues.iterator(),
this.readyClassQueues.size(), maxQueuesPerReportCategory);
代码示例来源:origin: google/guava
void checkEmpty(BlockingQueue q) {
try {
assertTrue(q.isEmpty());
assertEquals(0, q.size());
assertNull(q.peek());
assertNull(q.poll());
assertNull(q.poll(0, MILLISECONDS));
assertEquals("[]", q.toString());
assertTrue(Arrays.equals(q.toArray(), new Object[0]));
assertFalse(q.iterator().hasNext());
try {
q.element();
shouldThrow();
} catch (NoSuchElementException success) {
}
try {
q.iterator().next();
shouldThrow();
} catch (NoSuchElementException success) {
}
try {
q.remove();
shouldThrow();
} catch (NoSuchElementException success) {
}
} catch (InterruptedException ie) {
threadUnexpectedException(ie);
}
}
代码示例来源:origin: apache/geode
for (Iterator<GatewaySenderEventImpl> iterator = peekedEvents.iterator(); iterator
.hasNext();) {
GatewaySenderEventImpl event = iterator.next();
代码示例来源:origin: mpetazzoni/ttorrent
private void processWriteTasks() {
final Iterator<WriteTask> iterator = myWriteQueue.iterator();
while (iterator.hasNext()) {
WriteTask writeTask = iterator.next();
代码示例来源:origin: ben-manes/caffeine
void checkEmpty(BlockingQueue q) {
try {
assertTrue(q.isEmpty());
assertEquals(0, q.size());
assertNull(q.peek());
assertNull(q.poll());
assertNull(q.poll(0, MILLISECONDS));
assertEquals(q.toString(), "[]");
assertTrue(Arrays.equals(q.toArray(), new Object[0]));
assertFalse(q.iterator().hasNext());
try {
q.element();
shouldThrow();
} catch (NoSuchElementException success) {}
try {
q.iterator().next();
shouldThrow();
} catch (NoSuchElementException success) {}
try {
q.remove();
shouldThrow();
} catch (NoSuchElementException success) {}
} catch (InterruptedException fail) { threadUnexpectedException(fail); }
}
代码示例来源:origin: jankotek/mapdb
void checkEmpty(BlockingQueue q) {
try {
assertTrue(q.isEmpty());
assertEquals(0, q.size());
assertNull(q.peek());
assertNull(q.poll());
assertNull(q.poll(randomExpiredTimeout(), randomTimeUnit()));
assertEquals(q.toString(), "[]");
assertTrue(Arrays.equals(q.toArray(), new Object[0]));
assertFalse(q.iterator().hasNext());
try {
q.element();
shouldThrow();
} catch (NoSuchElementException success) {}
try {
q.iterator().next();
shouldThrow();
} catch (NoSuchElementException success) {}
try {
q.remove();
shouldThrow();
} catch (NoSuchElementException success) {}
} catch (InterruptedException fail) { threadUnexpectedException(fail); }
}
代码示例来源:origin: i2p/i2p.i2p
/**
* Remove all Request messages from the queue.
* Does not send a cancel message.
* @since 0.8.2
*/
void cancelRequestMessages() {
synchronized(sendQueue) {
for (Iterator<Message> it = sendQueue.iterator(); it.hasNext(); ) {
if (it.next().type == Message.REQUEST)
it.remove();
}
}
}
代码示例来源:origin: i2p/i2p.i2p
int queuedBytes()
{
int total = 0;
synchronized(sendQueue)
{
Iterator<Message> it = sendQueue.iterator();
while (it.hasNext())
{
Message m = it.next();
if (m.type == Message.PIECE)
total += m.length;
}
}
return total;
}
代码示例来源:origin: moagrius/TileView
public void queue(Set<Tile> renderSet) {
Iterator<Runnable> iterator = getQueue().iterator();
while (iterator.hasNext()) {
Tile tile = (Tile) iterator.next();
if (!renderSet.contains(tile)) {
tile.destroy(false);
iterator.remove();
}
}
for (Tile tile : renderSet) {
if (isShutdownOrTerminating()) {
return;
}
if (tile.getState() == Tile.State.IDLE) {
execute(tile);
}
}
}
代码示例来源:origin: i2p/i2p.i2p
/** send cancel */
void sendCancel(Request req)
{
// See if it is still in our send queue
synchronized(sendQueue)
{
Iterator<Message> it = sendQueue.iterator();
while (it.hasNext())
{
Message m = it.next();
if (m.type == Message.REQUEST
&& m.piece == req.getPiece()
&& m.begin == req.off
&& m.length == req.len)
it.remove();
}
}
// Always send, just to be sure it it is really canceled.
Message m = new Message(Message.CANCEL, req.getPiece(), req.off, req.len);
addMessage(m);
}
代码示例来源:origin: i2p/i2p.i2p
void sendRequest(Request req)
{
// Check for duplicate requests to deal with fibrillating i2p-bt
// (multiple choke/unchokes received cause duplicate requests in the queue)
synchronized(sendQueue)
{
Iterator<Message> it = sendQueue.iterator();
while (it.hasNext())
{
Message m = it.next();
if (m.type == Message.REQUEST && m.piece == req.getPiece() &&
m.begin == req.off && m.length == req.len)
{
if (_log.shouldLog(Log.DEBUG))
_log.debug("Discarding duplicate request " + req + " to peer " + peer);
return;
}
}
}
Message m = new Message(Message.REQUEST, req.getPiece(), req.off, req.len);
addMessage(m);
req.sendTime = System.currentTimeMillis();
}
内容来源于网络,如有侵权,请联系作者删除!