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

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

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

ConcurrentHashMap.size介绍

[英]Returns the number of key-value mappings in this map. If the map contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
[中]返回此映射中的键值映射数。如果映射包含多个整数。最大值元素,返回整数。最大值。

代码示例

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

public void dumpOpenManagers() {
  int estimatedSize = openManagers.size();
  logger.trace("---- Begin open HBase store manager list ({} managers) ----", estimatedSize);
  for (HBaseStoreManager m : openManagers.keySet()) {
    logger.trace("Manager {} opened at:", m, openManagers.get(m));
  }
  logger.trace("----   End open HBase store manager list ({} managers)  ----", estimatedSize);
}

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

if ((tasksToKill.size() > 0 && tasksToKill.size() == taskGroup.tasks.size()) ||
  (taskGroup.tasks.size() == 0
   && pendingCompletionTaskGroups.getOrDefault(groupId, new CopyOnWriteArrayList<>()).size() == 0)) {
 partitionGroups.get(groupId).replaceAll((partition, sequence) -> getNotSetMarker());

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

private void removeFromCacheForServerToConstructedCQName(final String cqName,
  ClientProxyMembershipID clientProxyMembershipID) {
 ConcurrentHashMap<ClientProxyMembershipID, String> cache = serverCqNameCache.get(cqName);
 if (cache != null) {
  cache.remove(clientProxyMembershipID);
  if (cache.size() == 0) {
   serverCqNameCache.remove(cqName);
  }
 }
}

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

public void dump(PrintWriter pwriter) {
  pwriter.print("Sets (");
  pwriter.print(expiryMap.size());
  pwriter.print(")/(");
  pwriter.print(elemMap.size());
  pwriter.println("):");
  ArrayList<Long> keys = new ArrayList<Long>(expiryMap.keySet());
  Collections.sort(keys);
  for (long time : keys) {
    Set<E> set = expiryMap.get(time);
    if (set != null) {
      pwriter.print(set.size());
      pwriter.print(" expire at ");
      pwriter.print(Time.elapsedTimeToDate(time));
      pwriter.println(":");
      for (E elem : set) {
        pwriter.print("\t");
        pwriter.println(elem.toString());
      }
    }
  }
}

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

public boolean skipFailureLogging(DistributionLocatorId locatorId) {
 boolean skipLogging = false;
 if (this.failureLogInterval.size() < FAILURE_MAP_MAXSIZE) {
  long[] logInterval = this.failureLogInterval.get(locatorId);
  if (logInterval == null) {
   logInterval = this.failureLogInterval.putIfAbsent(locatorId,
     new long[] {System.currentTimeMillis(), 1000});
  }
  if (logInterval != null) {
   long currentTime = System.currentTimeMillis();
   if ((currentTime - logInterval[0]) < logInterval[1]) {
    skipLogging = true;
   } else {
    logInterval[0] = currentTime;
    if (logInterval[1] <= (FAILURE_LOG_MAX_INTERVAL / 2)) {
     logInterval[1] *= 2;
    }
   }
  }
 }
 return skipLogging;
}

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

AtomicLong counter = recentItems.get( item );
if ( counter != null )
  if ( recentItems.size() >= maxItems )
      while ( recentItems.size() >= maxItems )

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

if (this.failureLogInterval.size() < FAILURE_MAP_MAXSIZE) {
 long[] logInterval = this.failureLogInterval.get(batchId);
 if (logInterval == null) {
  logInterval = this.failureLogInterval.putIfAbsent(batchId,

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

public JsonCapsuleFactory minify(JSONObject json) {
  if (json == null) return null;
  JSONObject minified = new JSONObject(true);
  for (String key: json.keySet()) {
    String s = this.key2short.get(key);
    if (s == null) synchronized(this.key2short) {
      s = this.key2short.get(key);
      if (s == null) {
        s = Integer.toHexString(this.key2short.size());
        this.key2short.put(key, s);
        this.short2key.put(s, key);
      }
    }
    minified.put(s, json.get(key));
  }
  return new JsonCapsuleFactory(minified);
}

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

/**
 * Select a format from a custom pattern.
 *
 * @param pattern  pattern specification
 * @throws IllegalArgumentException if the pattern is invalid
 * @see #appendPatternTo
 */
private static DateTimeFormatter createFormatterForPattern(String pattern) {
  if (pattern == null || pattern.length() == 0) {
    throw new IllegalArgumentException("Invalid pattern specification");
  }
  DateTimeFormatter formatter = cPatternCache.get(pattern);
  if (formatter == null) {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    parsePatternTo(builder, pattern);
    formatter = builder.toFormatter();
    if (cPatternCache.size() < PATTERN_CACHE_SIZE) {
      // the size check is not locked against concurrent access,
      // but is accepted to be slightly off in contention scenarios.
      DateTimeFormatter oldFormatter = cPatternCache.putIfAbsent(pattern, formatter);
      if (oldFormatter != null) {
        formatter = oldFormatter;
      }
    }
  }
  return formatter;
}

代码示例来源:origin: Atmosphere/atmosphere

public <T extends Broadcaster> T lookup(Class<T> c, Object id, boolean createIfNull, boolean unique) {
  synchronized (c) {
    logger.trace("About to create {}", id);
    if (unique && store.get(id) != null) {
      throw new IllegalStateException("Broadcaster already exists " + id + ". Use BroadcasterFactory.lookup instead");
    T b = (T) store.get(id);
    logger.trace("Looking in the store using {} returned {}", id, b);
    if (b != null && !c.isAssignableFrom(b.getClass())) {
      Broadcaster nb = store.get(id);
      if (nb == null) {
        nb = createBroadcaster(c, id);
        logger.trace("Added Broadcaster {} . Factory size: {}", id, store.size());

代码示例来源:origin: joda-time/joda-time

/**
 * Select a format from a custom pattern.
 *
 * @param pattern  pattern specification
 * @throws IllegalArgumentException if the pattern is invalid
 * @see #appendPatternTo
 */
private static DateTimeFormatter createFormatterForPattern(String pattern) {
  if (pattern == null || pattern.length() == 0) {
    throw new IllegalArgumentException("Invalid pattern specification");
  }
  DateTimeFormatter formatter = cPatternCache.get(pattern);
  if (formatter == null) {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    parsePatternTo(builder, pattern);
    formatter = builder.toFormatter();
    if (cPatternCache.size() < PATTERN_CACHE_SIZE) {
      // the size check is not locked against concurrent access,
      // but is accepted to be slightly off in contention scenarios.
      DateTimeFormatter oldFormatter = cPatternCache.putIfAbsent(pattern, formatter);
      if (oldFormatter != null) {
        formatter = oldFormatter;
      }
    }
  }
  return formatter;
}

代码示例来源:origin: SeldonIO/seldon-server

public List<State> getAllMinHashes(long time)
{
  List<State> states = new ArrayList<>();
  for(Long id : mhcs.keySet())
  {
    int count = mhcs.get(id).getCount(time);
    if (count >= minActivity)
    {
      List<Long> mh = mhcs.get(id).getMinHashes(time);
      if (mh != null && mh.size() > 0)
        states.add(new State(id,mh));
    }
    else if (count == 0)
    {
      mhcs.remove(id);
      //System.out.println("removed "+id);
    }
  }
  System.out.println("Raw number of minHashes "+mhcs.size()+" but will return "+states.size()+" with minActiviy filter at "+minActivity);
  return states;
}

代码示例来源:origin: PipelineAI/pipeline

@SuppressWarnings("unchecked")
public T get(HystrixConcurrencyStrategy concurrencyStrategy) {
  /*
   * 1) Fetch RequestVariable implementation from cache.
   * 2) If no implementation is found in cache then construct from factory.
   * 3) Cache implementation from factory as each object instance needs to be statically cached to be relevant across threads.
   */
  RVCacheKey key = new RVCacheKey(this, concurrencyStrategy);
  HystrixRequestVariable<?> rvInstance = requestVariableInstance.get(key);
  if (rvInstance == null) {
    requestVariableInstance.putIfAbsent(key, concurrencyStrategy.getRequestVariable(lifeCycleMethods));
    /*
     * A safety check to help debug problems if someone starts injecting dynamically created HystrixConcurrencyStrategy instances - which should not be done and has no good reason to be done.
     * 
     * The 100 value is arbitrary ... just a number far higher than we should see.
     */
    if (requestVariableInstance.size() > 100) {
      logger.warn("Over 100 instances of HystrixRequestVariable are being stored. This is likely the sign of a memory leak caused by using unique instances of HystrixConcurrencyStrategy instead of a single instance.");
    }
  }
  return (T) requestVariableInstance.get(key).get();
}

代码示例来源:origin: JodaOrg/joda-time

/**
 * Select a format from a custom pattern.
 *
 * @param pattern  pattern specification
 * @throws IllegalArgumentException if the pattern is invalid
 * @see #appendPatternTo
 */
private static DateTimeFormatter createFormatterForPattern(String pattern) {
  if (pattern == null || pattern.length() == 0) {
    throw new IllegalArgumentException("Invalid pattern specification");
  }
  DateTimeFormatter formatter = cPatternCache.get(pattern);
  if (formatter == null) {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    parsePatternTo(builder, pattern);
    formatter = builder.toFormatter();
    if (cPatternCache.size() < PATTERN_CACHE_SIZE) {
      // the size check is not locked against concurrent access,
      // but is accepted to be slightly off in contention scenarios.
      DateTimeFormatter oldFormatter = cPatternCache.putIfAbsent(pattern, formatter);
      if (oldFormatter != null) {
        formatter = oldFormatter;
      }
    }
  }
  return formatter;
}

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

MetricsMonitor.getDumpTaskMonitor().set(tasks.size());
TaskProcessor processor = this.taskProcessors.get(entry.getKey());
if (null == processor) {

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

activelyReadingTaskGroups.values()
               .stream()
               .filter(taskGroup -> taskGroup.tasks.size() < ioConfig.getReplicas())
               .collect(Collectors.toList())
);
  log.info("Creating new task group [%d] for partitions %s", groupId, partitionGroups.get(groupId).keySet());
 if (ioConfig.getReplicas() > taskGroup.tasks.size()) {
  log.info(
    "Number of tasks [%d] does not match configured numReplicas [%d] in task group [%d], creating more tasks",
    taskGroup.tasks.size(), ioConfig.getReplicas(), groupId
  );
  createTasksForGroup(groupId, ioConfig.getReplicas() - taskGroup.tasks.size());
  createdTask = true;

代码示例来源:origin: internetarchive/heritrix3

startTime = System.currentTimeMillis();
logger.fine(dbName + " start sizes: disk " + this.diskMap.size() +
  ", mem " + this.memMap.size());
SoftEntry<V> entry = memMap.get(key);
if (entry != null) {
  (System.currentTimeMillis() - startTime) + "ms. " +
  "Finish sizes: disk " +
  this.diskMap.size() + ", mem " + this.memMap.size());

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

} else if (tmp instanceof ConcurrentHashMap) {
  ConcurrentHashMap<String, CacheWrapper<Object>> hash = (ConcurrentHashMap<String, CacheWrapper<Object>>) tmp;
  if (hash.size() > 0) {
    this.changeListener.cacheChange(hash.size());
    .get(cacheKey);
if (null != hash) {
  tmp = hash.remove(hfield);

代码示例来源:origin: org.freemarker/freemarker

throws InvalidFormatParametersException {
CacheKey cacheKey = new CacheKey(params, locale);
NumberFormat jFormat = GLOBAL_FORMAT_CACHE.get(cacheKey);
if (jFormat == null) {
  if ("number".equals(params)) {
  if (GLOBAL_FORMAT_CACHE.size() >= LEAK_ALERT_NUMBER_FORMAT_CACHE_SIZE) {
    boolean triggered = false;
    synchronized (JavaTemplateNumberFormatFactory.class) {
      if (GLOBAL_FORMAT_CACHE.size() >= LEAK_ALERT_NUMBER_FORMAT_CACHE_SIZE) {
        triggered = true;
        GLOBAL_FORMAT_CACHE.clear();

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

@Override
public void reportCpuMetrics(XLearningContainerId containerId, String cpuMetrics) {
 if (this.containersCpuMetrics.get(containerId).size() == 0) {
  Gson gson = new GsonBuilder()
    .registerTypeAdapter(
  for (String str : map.keySet()) {
   LinkedBlockingDeque<Object> queue = new LinkedBlockingDeque<>();
   queue.add(map.get(str));
   this.containersCpuMetrics.get(containerId).put(str, queue);
   this.containersCpuStatistics.get(containerId).put(str, new ContainerMetricsStatisticsTuple(Double.parseDouble(new Gson().fromJson((JsonArray)map.get(str), ArrayList.class).get(1).toString())));
  for (String str : map.keySet()) {
   if (this.containersCpuMetrics.get(containerId).keySet().contains(str)) {
    if (this.containersCpuMetrics.get(containerId).get(str).size() < 1800) {
     this.containersCpuMetrics.get(containerId).get(str).add(map.get(str));
    } else {

相关文章