当前位置: 首页>>代码示例>>Java>>正文


Java ConcurrentHashMap.size方法代码示例

本文整理汇总了Java中java.util.concurrent.ConcurrentHashMap.size方法的典型用法代码示例。如果您正苦于以下问题:Java ConcurrentHashMap.size方法的具体用法?Java ConcurrentHashMap.size怎么用?Java ConcurrentHashMap.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.ConcurrentHashMap的用法示例。


在下文中一共展示了ConcurrentHashMap.size方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getQueryStats

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
protected QueryStats getQueryStats(String sql) {
    if (sql==null) sql = "";
    ConcurrentHashMap<String,QueryStats> queries = SlowQueryReport.this.queries;
    if (queries==null) {
        if (log.isWarnEnabled()) log.warn("Connection has already been closed or abandoned");
        return null;
    }
    QueryStats qs = queries.get(sql);
    if (qs == null) {
        qs = new QueryStats(sql);
        if (queries.putIfAbsent(sql,qs)!=null) {
            qs = queries.get(sql);
        } else {
            //we added a new element, see if we need to remove the oldest
            if (queries.size() > maxQueries) {
                removeOldest(queries);
            }
        }
    }
    return qs;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:22,代码来源:SlowQueryReport.java

示例2: writeTransform

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
@Override
public Object writeTransform(Field f, Class<?> clazz, Object originalValue) {
  if (f.getType().equals(ConcurrentHashMap.class)) {
    Object[] result = null;
    if (originalValue != null) {
      ConcurrentHashMap<?, ?> m = (ConcurrentHashMap<?, ?>) originalValue;
      result = new Object[m.size() * 2];
      int i = 0;
      for (Map.Entry<?, ?> e : m.entrySet()) {
        result[i++] = e.getKey();
        result[i++] = e.getValue();
      }
    }
    return result;
  } else {
    return super.writeTransform(f, clazz, originalValue);
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:19,代码来源:AutoSerializableJUnitTest.java

示例3: size

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
public int size() {
    if (k1_k2V_map.size() == 0) return 0;

    int result = 0;
    for (ConcurrentHashMap<K2, V> k2V_map : k1_k2V_map.values()) {
        result += k2V_map.size();
    }
    return result;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:DoubleKeyValueMap.java

示例4: removeOldest

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
/**
 * Sort QueryStats by last invocation time
 * @param queries
 */
protected void removeOldest(ConcurrentHashMap<String,QueryStats> queries) {
    ArrayList<QueryStats> list = new ArrayList<QueryStats>(queries.values());
    Collections.sort(list, queryStatsComparator);
    int removeIndex = 0;
    while (queries.size() > maxQueries) {
        String sql = list.get(removeIndex).getQuery();
        queries.remove(sql);
        if (log.isDebugEnabled()) log.debug("Removing slow query, capacity reached:"+sql);
        removeIndex++;
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:16,代码来源:SlowQueryReport.java

示例5: HeartBeatTask

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
public HeartBeatTask(Client client, ConcurrentHashMap<Peer,Integer> peerList, int hbPort, int swPort) {
    this.peerList = peerList;
    this.hbPort = hbPort;
    this.swPort = swPort;
    this.size =peerList.size();
    HeartBeatTask.client = client;
}
 
开发者ID:CrypDist,项目名称:CrypDist,代码行数:8,代码来源:HeartBeatTask.java

示例6: sayHelloWithHashMap

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
@Override
public String sayHelloWithHashMap(ConcurrentHashMap<String, String> receivedHashMap)
        throws RemoteException {
    int hashMapSize = 0;

    hashMapSize = receivedHashMap.size();
    String response = "Hello with hashMapSize == " + hashMapSize;
    return response;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:HelloImpl.java

示例7: testWeakKey

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
/**
 * Example using a Cleaner to remove WeakKey references from a Map.
 */
@Test
void testWeakKey() {
    ConcurrentHashMap<WeakKey<String>, String> map = new ConcurrentHashMap<>();
    Cleaner cleaner = Cleaner.create();
    String key = new String("foo");  //  ensure it is not interned
    String data = "bar";

    map.put(new WeakKey<>(key, cleaner, map), data);

    WeakKey<String> k2 = new WeakKey<>(key, cleaner, map);

    Assert.assertEquals(map.get(k2), data, "value should be found in the map");
    key = null;
    System.gc();
    Assert.assertNotEquals(map.get(k2), data, "value should not be found in the map");

    final long CYCLE_MAX = Utils.adjustTimeout(30L);
    for (int i = 1; map.size() > 0 && i < CYCLE_MAX; i++) {
        map.forEach( (k, v) -> System.out.printf("    k: %s, v: %s%n", k, v));
        try {
            Thread.sleep(10L);
        } catch (InterruptedException ie) {}
    }
    Assert.assertEquals(map.size(), 0, "Expected map to be empty;");
    cleaner = null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:CleanerTest.java

示例8: removeTargetIfRequired

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
/**
 * Remove the target.
 *
 * @param subscribedMethods the subscribed methods.
 * @param mTargetMap        the target map.
 * @param targetObject      the target object.
 */
private void removeTargetIfRequired(ConcurrentHashMap<String, SubscriberHolder> subscribedMethods,
                                    ConcurrentHashMap<Object,
                                            ConcurrentHashMap<String, SubscriberHolder>> mTargetMap,
                                    Object targetObject) {
    if (subscribedMethods.size() == 0) {
        mTargetMap.remove(targetObject);
    }
}
 
开发者ID:MindorksOpenSource,项目名称:NYBus,代码行数:16,代码来源:NYBusDriver.java

示例9: removeEventIfRequired

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
/**
 * Remove the event.
 *
 * @param mTargetMap               the target map.
 * @param mEventsToTargetsMapEntry the event to target map entry.
 */
private void removeEventIfRequired(ConcurrentHashMap<Object,
        ConcurrentHashMap<String, SubscriberHolder>> mTargetMap,
                                   Map.Entry<Class<?>, ConcurrentHashMap<Object,
                                           ConcurrentHashMap<String,
                                                   SubscriberHolder>>> mEventsToTargetsMapEntry) {
    if (mTargetMap.size() == 0) {
        mEventsToTargetsMap.remove(mEventsToTargetsMapEntry.getKey());
    }
}
 
开发者ID:MindorksOpenSource,项目名称:NYBus,代码行数:16,代码来源:NYBusDriver.java

示例10: manageCache

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
private <T> T manageCache(ConcurrentHashMap<Integer, WithUseCount<T>> cache, Accessor<T> accessor, int n, FieldSelector fieldSelector, int limit) throws IOException
{
    Integer key = Integer.valueOf(n);
    WithUseCount<T> value = cache.get(key);
    if (value == null)
    {
        T made = accessor.get(n, fieldSelector);
        value = new WithUseCount<T>(made, n);
        cache.put(key, value);

        // resize

        if (limit >= 0)
        {
            if (cache.size() >= limit)
            {
                HashMap<Integer, WithUseCount<T>> keep = new HashMap<Integer, WithUseCount<T>>();
                WithUseCount<T>[] existing = new WithUseCount[0];
                synchronized (cache)
                {
                    existing = cache.values().toArray(existing);
                    cache.clear();
                }
                Arrays.sort(existing);

                for (WithUseCount<T> current : existing)
                {
                    keep.put(Integer.valueOf(current.doc), current);
                    if ((current.count.get() == 0) || (keep.size() > (limit / 4)))
                    {
                        break;
                    }
                }
                keep.put(key, value);
                cache.putAll(keep);
            }
        }
    }
    else
    {
        value.count.getAndIncrement();
    }
    return value.object;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:45,代码来源:ReferenceCountingReadOnlyIndexReaderFactory.java

示例11: main

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
public static void main(String[] args) {
    ConcurrentHashMap map = new ConcurrentHashMap();
    map.put(1,2);
    map.get(1);
    map.size();
}
 
开发者ID:baohongfei,项目名称:think-in-java,代码行数:7,代码来源:ConcurrentHashMapTest.java

示例12: initClusterCenters

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
/** Initialize cluster centers. */
private Vector[] initClusterCenters(SparseDistributedMatrix points, int k) {
    // Initialize empty centers and point costs.
    int ptsCnt = points.rowSize();

    String cacheName = ((SparseDistributedMatrixStorage)points.getStorage()).cacheName();

    // Initialize the first center to a random point.
    Vector sample = localCopyOf(points.viewRow(rnd.nextInt(ptsCnt)));

    List<Vector> centers = new ArrayList<>();
    List<Vector> newCenters = new ArrayList<>();
    newCenters.add(sample);
    centers.add(sample);

    final ConcurrentHashMap<Integer, Double> costs = new ConcurrentHashMap<>();

    // On each step, sample 2 * k points on average with probability proportional
    // to their squared distance from the centers. Note that only distances between points
    // and new centers are computed in each iteration.
    int step = 0;
    UUID uid = points.getUUID();

    while (step < initSteps) {
        // We assume here that costs can fit into memory of one node.
        ConcurrentHashMap<Integer, Double> newCosts = getNewCosts(points, newCenters, cacheName);

        // Merge costs with new costs.
        for (Integer ind : newCosts.keySet())
            costs.merge(ind, newCosts.get(ind), Math::min);

        double sumCosts = costs.values().stream().mapToDouble(Double::valueOf).sum();

        newCenters = getNewCenters(k, costs, uid, sumCosts, cacheName);
        centers.addAll(newCenters);

        step++;
    }

    List<Vector> distinctCenters = centers.stream().distinct().collect(Collectors.toList());

    if (distinctCenters.size() <= k)
        return distinctCenters.toArray(new Vector[] {});
    else {
        // Finally, we might have a set of more than k distinct candidate centers; weight each
        // candidate by the number of points in the dataset mapping to it and run a local k-means++
        // on the weighted centers to pick k of them
        ConcurrentHashMap<Integer, Integer> centerInd2Weight = weightCenters(uid, distinctCenters, cacheName);

        List<Double> weights = new ArrayList<>(centerInd2Weight.size());

        for (int i = 0; i < distinctCenters.size(); i++)
            weights.add(i, Double.valueOf(centerInd2Weight.getOrDefault(i, 0)));

        DenseLocalOnHeapMatrix dCenters = MatrixUtil.fromList(distinctCenters, true);

        return new KMeansLocalClusterer(getDistanceMeasure(), 30, seed).cluster(dCenters, k, weights).centers();
    }
}
 
开发者ID:Luodian,项目名称:Higher-Cloud-Computing-Project,代码行数:60,代码来源:KMeansDistributedClusterer.java


注:本文中的java.util.concurrent.ConcurrentHashMap.size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。