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

x33g5p2x  于2022-01-18 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(201)

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

ConcurrentSkipListMap.size介绍

[英]Returns the number of key-value mappings in this map. If this map contains more than Integer.MAX_VALUE elements, it returns Integer.MAX_VALUE.

Beware that, unlike in most collections, this method is NOT a constant-time operation. Because of the asynchronous nature of these maps, determining the current number of elements requires traversing them all to count them. Additionally, it is possible for the size to change during execution of this method, in which case the returned result will be inaccurate. Thus, this method is typically not very useful in concurrent applications.
[中]返回此映射中的键值映射数。如果此映射包含多个整数。最大值元素,它返回整数。最大值。
请注意,与大多数集合不同,此方法不是恒定时间操作。由于这些映射的异步性质,确定当前元素的数量需要遍历所有元素以对其进行计数。此外,在执行此方法的过程中,可能会更改大小,在这种情况下,返回的结果将不准确。因此,这种方法在并发应用程序中通常不是很有用。

代码示例

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

@Override
public int getNumberOfSegmentsInQueue()
{
 return segmentsToLoad.size();
}

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

@Override
public int getNumberOfSegmentsInQueue()
{
 return segmentsToLoad.size();
}

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

/**
 * Get the number of regions in transition.
 */
public int getRegionsInTransitionCount() {
 return regionInTransition.size();
}

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

@Override
public long size() {
 return map.size();
}

代码示例来源:origin: lealone/Lealone

@Override
public int size() {
  return skipListMap.size();
}

代码示例来源:origin: Alluxio/alluxio

private int weight(ListingCacheEntry entry) {
 Preconditions.checkNotNull(entry);
 Preconditions.checkNotNull(entry.mChildren);
 // Add 1 to take the key into account.
 return entry.mChildren.size() + 1;
}

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

@Override
protected int getCacheSize( FileCache<ConcurrentSkipListMap<Long, LlapDataBuffer>> fc) {
 return fc.getCache().size();
}

代码示例来源:origin: io.dropwizard.metrics/metrics-core

@Override
public int size() {
  trim();
  return measurements.size();
}

代码示例来源:origin: networknt/light-4j

@Override
public int size() {
  trim();
  return measurements.size();
}

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

public ArrayList<RegionState> getRegionStates() {
 final ArrayList<RegionState> regions = new ArrayList<RegionState>(regionsMap.size());
 for (RegionStateNode node: regionsMap.values()) {
  regions.add(node.toRegionState());
 }
 return regions;
}

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

public List<RegionState> getRegionsStateInTransition() {
 final List<RegionState> rit = new ArrayList<RegionState>(regionInTransition.size());
 for (RegionStateNode node: regionInTransition.values()) {
  rit.add(node.toRegionState());
 }
 return rit;
}

代码示例来源:origin: qunarcorp/qmq

private void tryCleanExpiredSnapshot() {
  try {
    while (true) {
      if (snapshots.size() <= config.getCheckpointRetainCount()) {
        return;
      }
      removeOldestSnapshot();
    }
  } catch (Throwable e) {
    LOG.error("try clean expired snapshot file failed.", e);
  }
}

代码示例来源:origin: qunarcorp/qmq

Map<Long, Long> countSegments() {
  final Map<Long, Long> offsets = new HashMap<>(segments.size());
  segments.values().forEach(segment -> offsets.put(segment.getSegmentBaseOffset(), segment.getWrotePosition()));
  return offsets;
}

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

public List<RegionState> getRegionFailedOpen() {
 if (regionFailedOpen.isEmpty()) return Collections.emptyList();
 ArrayList<RegionState> regions = new ArrayList<RegionState>(regionFailedOpen.size());
 for (RegionFailedOpen r: regionFailedOpen.values()) {
  regions.add(r.getRegionStateNode().toRegionState());
 }
 return regions;
}

代码示例来源:origin: qunarcorp/qmq

public void deleteSegments(Predicate<LogSegment> predicate, DeleteHook afterDeleted) {
  int count = segments.size();
  if (count <= 1) return;
  for (final Map.Entry<Long, LogSegment> entry : segments.entrySet()) {
    if (count <= 1) return;
    final LogSegment segment = entry.getValue();
    if (predicate.test(segment)) {
      if (deleteSegment(entry.getKey(), segment)) {
        count = count - 1;
        executeHook(afterDeleted, segment);
        LOG.info("remove expired segment success. segment: {}", segment);
      } else {
        LOG.warn("remove expired segment failed. segment: {}", segment);
        return;
      }
    }
  }
}

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

/**
 * Removes cached affinity instances with affinity topology versions less than {@code topVer}.
 *
 * @param topVer topology version.
 */
public void removeCachedAffinity(AffinityTopologyVersion topVer) {
  assert topVer != null;
  int oldSize = affMap.size();
  Iterator<Map.Entry<AffinityAssignmentKey, IgniteInternalFuture<AffinityInfo>>> it =
    affMap.headMap(new AffinityAssignmentKey(topVer)).entrySet().iterator();
  while (it.hasNext()) {
    Map.Entry<AffinityAssignmentKey, IgniteInternalFuture<AffinityInfo>> entry = it.next();
    assert entry.getValue() != null;
    if (!entry.getValue().isDone())
      continue;
    it.remove();
  }
  if (log.isDebugEnabled())
    log.debug("Affinity cached values were cleared: " + (oldSize - affMap.size()));
}

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

private void rescale(long now, long next) {
  if (nextScaleTime.compareAndSet(next, now + RESCALE_THRESHOLD)) {
    lockForRescale();
    try {
      final long oldStartTime = startTime;
      this.startTime = currentTimeInSeconds();
      final double scalingFactor = exp(-alpha * (startTime - oldStartTime));
      final ArrayList<Double> keys = new ArrayList<>(values.keySet());
      for (Double key : keys) {
        final WeightedSnapshot.WeightedSample sample = values.remove(key);
        final WeightedSnapshot.WeightedSample newSample =
            new WeightedSnapshot.WeightedSample(sample.value, sample.weight * scalingFactor);
        values.put(key * scalingFactor, newSample);
      }
      // make sure the counter is in sync with the number of stored samples.
      count.set(values.size());
    } finally {
      unlockForRescale();
    }
  }
}

代码示例来源:origin: networknt/light-4j

private void rescale(long now, long next) {
  if (nextScaleTime.compareAndSet(next, now + RESCALE_THRESHOLD)) {
    lockForRescale();
    try {
      final long oldStartTime = startTime;
      this.startTime = currentTimeInSeconds();
      final double scalingFactor = exp(-alpha * (startTime - oldStartTime));
      final ArrayList<Double> keys = new ArrayList<>(values.keySet());
      for (Double key : keys) {
        final WeightedSample sample = values.remove(key);
        final WeightedSample newSample = new WeightedSample(sample.value, sample.weight * scalingFactor);
        values.put(key * scalingFactor, newSample);
      }
      // make sure the counter is in sync with the number of stored samples.
      count.set(values.size());
    } finally {
      unlockForRescale();
    }
  }
}

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

/** {@inheritDoc} */
@Override public void printMemoryStats() {
  X.println(">>>");
  X.println(">>> Affinity processor memory stats [igniteInstanceName=" + ctx.igniteInstanceName() + ']');
  X.println(">>>   affMapSize: " + affMap.size());
}

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

@Test
public void testSize() throws Exception {
 assertEquals("Size should always be equal", m.size(), csm.size());
}

相关文章

ConcurrentSkipListMap类方法