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

x33g5p2x  于2022-01-17 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(180)

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

ConcurrentHashMap.entrySet介绍

[英]Returns a Set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.

The view's iterator is a "weakly consistent" iterator that will never throw ConcurrentModificationException, and guarantees to traverse elements as they existed upon construction of the iterator, and may (but is not guaranteed to) reflect any modifications subsequent to construction.
[中]返回此映射中包含的映射的集合视图。集合由映射支持,因此对映射的更改将反映在集合中,反之亦然。该集合支持元素移除,即通过迭代器从映射中移除相应的映射。移除,设置。移除、移除所有、保留和清除操作。它不支持添加或添加所有操作。
视图的迭代器是一个“弱一致性”迭代器,它永远不会抛出ConcurrentModificationException,并保证在构造迭代器时遍历元素,并且可能(但不保证)反映构造之后的任何修改。

代码示例

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

@Override
public Collection<V> values() {
  List<V> list = new ArrayList<V>();
  Set<Entry<K, ExpiryObject>> delegatedSet = delegateMap.entrySet();
  for (Entry<K, ExpiryObject> entry : delegatedSet) {
    ExpiryObject value = entry.getValue();
    list.add(value.getValue());
  }
  return list;
}

代码示例来源:origin: ben-manes/caffeine

EntryIterator(UnboundedLocalCache<K, V> cache) {
 this.cache = requireNonNull(cache);
 this.iterator = cache.data.entrySet().iterator();
}

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

protected static void addToCache(String key, String value) {
  myCrummyCache.putIfAbsent(key, value);
  int numToRemove = myCrummyCache.size() - CACHE_SIZE;
  if (numToRemove > 0) {
    //Remove something randomly...
    Iterator<Entry<String, String>> it = myCrummyCache.entrySet().iterator();
    for (; numToRemove > 0 && it.hasNext(); numToRemove--) {
      it.next();
      it.remove();
    }
  }
}

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

@Nullable
@Override
public InputRow nextRow()
{
 if (nextIterator.hasNext()) {
  return nextIterator.next();
 }
 for (Map.Entry<MessageQueue, ConcurrentSkipListSet<MessageExt>> entry : messageQueueTreeSetMap.entrySet()) {
  if (!entry.getValue().isEmpty()) {
   MessageExt message = entry.getValue().pollFirst();
   nextIterator = theParser.parseBatch(ByteBuffer.wrap(message.getBody())).iterator();
   windows
     .computeIfAbsent(entry.getKey(), k -> new ConcurrentSkipListSet<>())
     .add(message.getQueueOffset());
   return nextIterator.next();
  }
 }
 // should never happen.
 throw new RuntimeException("Unexpected Fatal Error! There should have been one row available.");
}

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

requesterRVV.memberToVersion.entrySet().iterator().next();
 Long gcVersion = this.memberToGCVersion.get(entry.getKey());
 return isGCVersionDominatedByOtherHolder(gcVersion, entry.getValue());
for (Map.Entry<T, Long> entry : this.memberToGCVersion.entrySet()) {
 T mbr = entry.getKey();
 Long gcVersion = entry.getValue();
 RegionVersionHolder<T> otherHolder = null;
 if (mbr.equals(requesterRVV.getOwnerId())) {

代码示例来源:origin: qiujiayu/AutoLoadCache

/**
 * 清除过期缓存
 */
private void cleanCache() {
  Iterator<Entry<String, Object>> iterator = cacheManager.getCache().entrySet().iterator();
  int cacheChanged = 0;
  int i = 0;
  while (iterator.hasNext()) {
    cacheChanged += removeExpiredItem(iterator);
    i++;
    if (i == 2000) {
      i = 0;
      try {
        Thread.sleep(0);// 触发操作系统立刻重新进行一次CPU竞争, 让其它线程获得CPU控制权的权力。
      } catch (InterruptedException e) {
        logger.error(e.getMessage(), e);
      }
    }
  }
  if (cacheChanged > 0) {
    cacheChange(cacheChanged);
  }
}

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

@Override
public boolean hasMore()
 if (nextIterator.hasNext()) {
  return true;
 DruidPullRequest earliestPullRequest = null;
 for (Map.Entry<String, Set<MessageQueue>> entry : topicQueueMap.entrySet()) {
  for (MessageQueue messageQueue : entry.getValue()) {
   ConcurrentSkipListSet<MessageExt> messages = messageQueueTreeSetMap.get(messageQueue);
   if (messages != null && !messages.isEmpty()) {
     LOGGER.error("Failed to fetch consume offset for queue: %s", entry.getKey());

代码示例来源:origin: thinkaurelius/titan

/**
   * Only use this in testing.
   * <p>
   * This deletes all entries in the global map of namespaces to mediators
   * whose namespace key equals the argument.
   *
   * @param prefix
   */
  public void clear(String namespace) {
    Iterator<Entry<String, LocalLockMediator<?>>> iter = mediators.entrySet().iterator();

    while (iter.hasNext()) {
      Entry<String, LocalLockMediator<?>> e = iter.next();

      if (e.getKey().equals(namespace)) {
        iter.remove();
      }
    }
  }
}

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

for (Map.Entry<Key, AggrColStatsList> entry : cacheStore.entrySet()) {
 Key key = entry.getKey();
 AggrColStatsList value = entry.getValue();
 if (lruKey == null) {
  lruKey = key;
  int currentIndex = 0;
  int deleteIndex = 0;
  for (Iterator<AggrColStats> iterator = candidateList.nodes.iterator(); iterator.hasNext();) {
   candidate = iterator.next();

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

other.memberToVersion.entrySet().iterator().next();
 RegionVersionHolder<T> holder = this.memberToVersion.get(entry.getKey());
 if (holder == null) {
  return false;
 } else {
  RegionVersionHolder<T> otherHolder = entry.getValue();
  return holder.isNewerThanOrCanFillExceptionsFor(otherHolder);
for (Map.Entry<T, RegionVersionHolder<T>> entry : this.memberToVersion.entrySet()) {
 T mbr = entry.getKey();
 RegionVersionHolder<T> holder = entry.getValue();
 RegionVersionHolder<T> otherHolder = other.memberToVersion.get(mbr);
 if (otherHolder != null) {

代码示例来源:origin: ben-manes/caffeine

ValuesIterator(UnboundedLocalCache<K, V> cache) {
 this.cache = requireNonNull(cache);
 this.iterator = cache.data.entrySet().iterator();
}

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

@Override
public Collection<V> values() {
  List<V> list = new ArrayList<V>();
  Set<Entry<K, ExpiryObject>> delegatedSet = delegateMap.entrySet();
  for (Entry<K, ExpiryObject> entry : delegatedSet) {
    ExpiryObject value = entry.getValue();
    list.add(value.getValue());
  }
  return list;
}

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

@JmxGetter(name = "getExceptionCountsAsString", description = "Returns counts of all the Exceptions seen so far as a string")
public String getExceptionCountsAsString() {
  StringBuilder result = new StringBuilder();
  Iterator<Entry<Class<? extends Exception>, AtomicLong>> itr = errCountMap.entrySet()
                                       .iterator();
  while(itr.hasNext()) {
    Entry<Class<? extends Exception>, AtomicLong> pair = itr.next();
    result.append(pair.getKey().getName() + ":" + pair.getValue().get() + "\n");
  }
  return result.toString();
}

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

@Override
public Iterator<Entry<RegionInfo,RegionSize>> iterator() {
 return store.entrySet().iterator();
}

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

private long getMaxPushCost() {
  long max = -1;
  for (Map.Entry<String, Long> entry : PushService.pushCostMap.entrySet()) {
    if (entry.getValue() > max) {
      max = entry.getValue();
    }
  }
  return max;
}

代码示例来源:origin: twitter/distributedlog

public void clear() {
  if (null != handlesMap) {
    Iterator<Map.Entry<LedgerDescriptor, RefCountedLedgerHandle>> handlesMapIter = handlesMap.entrySet().iterator();
    while (handlesMapIter.hasNext()) {
      Map.Entry<LedgerDescriptor, RefCountedLedgerHandle> entry = handlesMapIter.next();
      // Make it inaccessible through the map
      handlesMapIter.remove();
      // now close the ledger
      entry.getValue().forceClose();
    }
  }
}

代码示例来源:origin: sohutv/cachecloud

private Map<K, Long> createAsMap() {
  Map<K,Long> resultMap = new LinkedHashMap<K, Long>();
  if(map != null && !map.isEmpty()){
    for(Entry<K, AtomicLong> entry : map.entrySet()){
      resultMap.put(entry.getKey(), entry.getValue().get());
    }
  }
  return Collections.unmodifiableMap(resultMap);
}

代码示例来源:origin: com.h2database/h2

private void revertTemp(long storeVersion) {
  for (Iterator<Entry<Long, ConcurrentHashMap<Integer, Chunk>>> it =
            freedPageSpace.entrySet().iterator(); it.hasNext(); ) {
    Entry<Long, ConcurrentHashMap<Integer, Chunk>> entry = it.next();
    Long v = entry.getKey();
    if (v <= storeVersion) {
      it.remove();
    }
  }
  for (MVMap<?, ?> m : maps.values()) {
    m.removeUnusedOldVersions();
  }
}

代码示例来源:origin: sohutv/cachecloud

private Map<K, Long> createAsMap() {
  Map<K,Long> resultMap = new LinkedHashMap<K, Long>();
  if(map != null && !map.isEmpty()){
    for(Entry<K, AtomicLong> entry : map.entrySet()){
      resultMap.put(entry.getKey(), entry.getValue().get());
    }
  }
  return Collections.unmodifiableMap(resultMap);
}

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

private Map<Object, Long> getDecayedCallCounts() {
 Map<Object, Long> decayedCallCounts = new HashMap<>(callCounts.size());
 Iterator<Map.Entry<Object, List<AtomicLong>>> it =
   callCounts.entrySet().iterator();
 while (it.hasNext()) {
  Map.Entry<Object, List<AtomicLong>> entry = it.next();
  Object user = entry.getKey();
  Long decayedCount = entry.getValue().get(0).get();
  if (decayedCount > 0) {
   decayedCallCounts.put(user, decayedCount);
  }
 }
 return decayedCallCounts;
}

相关文章