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

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

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

LinkedBlockingQueue.remove介绍

[英]Removes a single instance of the specified element from this queue, if it is present. More formally, removes an element e such that o.equals(e), if this queue contains one or more such elements. Returns true if this queue contained the specified element (or equivalently, if this queue changed as a result of the call).
[中]从该队列中删除指定元素的单个实例(如果存在)。更正式地说,如果此队列包含一个或多个这样的元素,则删除元素e,使o.equals(e)。如果此队列包含指定的元素,则返回true(如果此队列因调用而更改,则返回等效值)。

代码示例

代码示例来源:origin: lingochamp/FileDownloader

public void expire(ITaskHunter.IStarter starter) {
  /**
   * @see LaunchTaskRunnable#equals(Object)
   */
  //noinspection SuspiciousMethodCalls
  mWorkQueue.remove(starter);
}

代码示例来源:origin: jankotek/mapdb

/**
 * removeAll(c) removes only those elements of c and reports true if changed
 */
public void testRemoveAll() {
  for (int i = 1; i < SIZE; ++i) {
    LinkedBlockingQueue q = populatedQueue(SIZE);
    LinkedBlockingQueue p = populatedQueue(i);
    assertTrue(q.removeAll(p));
    assertEquals(SIZE - i, q.size());
    for (int j = 0; j < i; ++j) {
      Integer x = (Integer)(p.remove());
      assertFalse(q.contains(x));
    }
  }
}

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

/**
 * Bring memory usage below totalMemoryAllowed.
 */
private synchronized void freeIndexInformation() {
 while (totalMemoryUsed.get() > totalMemoryAllowed) {
  String s = queue.remove();
  IndexInformation info = cache.remove(s);
  if (info != null) {
   totalMemoryUsed.addAndGet(-info.getSize());
  }
 }
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

public Runnable deleteByName(String name) {
  NamedRunnable e = (NamedRunnable) keysInProgress.remove(name);
  if (e != null) {
   e.cancel();
   super.remove(e);
  }
  return e;
 }
}

代码示例来源:origin: fengjiachun/Jupiter

@SuppressWarnings("all")
@Override
public void unregister(RegisterMeta meta) {
  if (!queue.remove(meta)) {
    registerMetaMap.remove(meta);
    doUnregister(meta);
  }
}

代码示例来源:origin: fengjiachun/Jupiter

@SuppressWarnings("all")
@Override
public void unregister(RegisterMeta meta) {
  if (!queue.remove(meta)) {
    registerMetaMap.remove(meta);
    doUnregister(meta);
  }
}

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

/**
 * When a COMMIT message is received, eventually this method is called,
 * which matches up the zxid from the COMMIT with (hopefully) the head of
 * the pendingTxns queue and hands it to the commitProcessor to commit.
 * @param zxid - must correspond to the head of pendingTxns if it exists
 */
public void commit(long zxid) {
  if (pendingTxns.size() == 0) {
    LOG.warn("Committing " + Long.toHexString(zxid)
        + " without seeing txn");
    return;
  }
  long firstElementZxid = pendingTxns.element().zxid;
  if (firstElementZxid != zxid) {
    LOG.error("Committing zxid 0x" + Long.toHexString(zxid)
        + " but next pending txn 0x"
        + Long.toHexString(firstElementZxid));
    System.exit(ExitCode.UNMATCHED_TXN_COMMIT.getValue());
  }
  Request request = pendingTxns.remove();
  commitProcessor.commit(request);
}

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

/**
 * This method removes the map from the cache if index information for this
 * map is loaded(size>0), index information entry in cache will not be 
 * removed if it is in the loading phrase(size=0), this prevents corruption  
 * of totalMemoryUsed. It should be called when a map output on this tracker 
 * is discarded.
 * @param mapId The taskID of this map.
 */
public void removeMap(String mapId) {
 IndexInformation info = cache.get(mapId);
 if (info == null || ((info != null) && isUnderConstruction(info))) {
  return;
 }
 info = cache.remove(mapId);
 if (info != null) {
  totalMemoryUsed.addAndGet(-info.getSize());
  if (!queue.remove(mapId)) {
   LOG.warn("Map ID" + mapId + " not found in queue!!");
  }
 } else {
  LOG.info("Map ID " + mapId + " not found in cache");
 }
}

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

@Override
public boolean remove(Object o) {
 if (super.remove(o)) {
  this.stats.remove();
  postRemove(o);
  return true;
 } else {
  return false;
 }
}

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

/**
 * When a COMMIT message is received, eventually this method is called, 
 * which matches up the zxid from the COMMIT with (hopefully) the head of
 * the pendingTxns queue and hands it to the commitProcessor to commit.
 * @param zxid - must correspond to the head of pendingTxns if it exists
 */
public void commit(long zxid) {
  if (pendingTxns.size() == 0) {
    LOG.warn("Committing " + Long.toHexString(zxid)
        + " without seeing txn");
    return;
  }
  long firstElementZxid = pendingTxns.element().zxid;
  if (firstElementZxid != zxid) {
    LOG.error("Committing zxid 0x" + Long.toHexString(zxid)
        + " but next pending txn 0x"
        + Long.toHexString(firstElementZxid));
    System.exit(12);
  }
  Request request = pendingTxns.remove();
  commitProcessor.commit(request);
}

代码示例来源:origin: lingochamp/FileDownloader

private void push() {
  final int delayMillis;
  synchronized (queueLock) {
    if (!disposingList.isEmpty()) {
      // is disposing.
      return;
    }
    if (waitingQueue.isEmpty()) {
      // not messenger need be handled.
      return;
    }
    if (!isIntervalValid()) {
      waitingQueue.drainTo(disposingList);
      delayMillis = 0;
    } else {
      delayMillis = INTERVAL;
      final int size = Math.min(waitingQueue.size(), SUB_PACKAGE_SIZE);
      for (int i = 0; i < size; i++) {
        disposingList.add(waitingQueue.remove());
      }
    }
  }
  handler.sendMessageDelayed(handler.obtainMessage(DISPOSE_MESSENGER_LIST, disposingList),
      delayMillis);
}

代码示例来源:origin: jankotek/mapdb

/**
 * Modifications do not cause iterators to fail
 */
public void testWeaklyConsistentIteration() {
  final LinkedBlockingQueue q = new LinkedBlockingQueue(3);
  q.add(one);
  q.add(two);
  q.add(three);
  for (Iterator it = q.iterator(); it.hasNext();) {
    q.remove();
    it.next();
  }
  assertEquals(0, q.size());
}

代码示例来源:origin: jankotek/mapdb

/**
 * An add following remove(x) succeeds
 */
public void testRemoveElementAndAdd() throws InterruptedException {
  LinkedBlockingQueue q = new LinkedBlockingQueue();
  assertTrue(q.add(new Integer(1)));
  assertTrue(q.add(new Integer(2)));
  assertTrue(q.remove(new Integer(1)));
  assertTrue(q.remove(new Integer(2)));
  assertTrue(q.add(new Integer(3)));
  assertNotNull(q.take());
}

代码示例来源:origin: jankotek/mapdb

/**
 * remove removes next element, or throws NSEE if empty
 */
public void testRemove() {
  LinkedBlockingQueue q = populatedQueue(SIZE);
  for (int i = 0; i < SIZE; ++i) {
    assertEquals(i, q.remove());
  }
  try {
    q.remove();
    shouldThrow();
  } catch (NoSuchElementException success) {}
}

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

session.transfer(messageFlowfile, REL_MESSAGE);
session.commit();
if (!mqttQueue.remove(mqttMessage) && logger.isWarnEnabled()) {
  logger.warn(new StringBuilder("FlowFile ")
      .append(messageFlowfile.getAttribute(CoreAttributes.UUID.key()))

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

outgoingBuffers.remove();

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

HdfsUtils.Pair<MessageId, List<Object>> pair = retryList.remove();
emitData(pair.getValue(), pair.getKey());
return;

代码示例来源:origin: jankotek/mapdb

/**
 * retainAll(c) retains only those elements of c and reports true if changed
 */
public void testRetainAll() {
  LinkedBlockingQueue q = populatedQueue(SIZE);
  LinkedBlockingQueue p = populatedQueue(SIZE);
  for (int i = 0; i < SIZE; ++i) {
    boolean changed = q.retainAll(p);
    if (i == 0)
      assertFalse(changed);
    else
      assertTrue(changed);
    assertTrue(q.containsAll(p));
    assertEquals(SIZE - i, q.size());
    p.remove();
  }
}

代码示例来源:origin: Impetus/Kundera

@Override
  public void run()
  {
    if (verifyConnection(cassandraHost))
    {
      if (((CassandraClientFactory) clientFactory).addCassandraHost(cassandraHost))
      {
        downedHostQueue.remove(cassandraHost);
      }
    }
  }
});

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

@Override
 public void run() {
  if(downedHostQueue.contains(cassandraHost) && verifyConnection(cassandraHost)) {
   if (connectionManager.addCassandraHost(cassandraHost)) {
    listenerHandler.fireOnHostRestored(cassandraHost);
    downedHostQueue.remove(cassandraHost);
   }
   return;
  }
 }
});

相关文章

微信公众号

最新文章

更多