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


Java ConcurrentHashMap.clear方法代码示例

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


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

示例1: testEquals

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
/**
 * Maps with same contents are equal
 */
public void testEquals() {
    ConcurrentHashMap map1 = map5();
    ConcurrentHashMap map2 = map5();
    assertEquals(map1, map2);
    assertEquals(map2, map1);
    map1.clear();
    assertFalse(map1.equals(map2));
    assertFalse(map2.equals(map1));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:ConcurrentHashMapTest.java

示例2: getCache

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
/**
 * 获取缓存数据
 * @param key
 * @return
 * 未设置或缓存有效时间已过都会返回null
 */
public static Object getCache(String key) {
    synchronized (key.intern()){
        if (StringUtils.isNotEmpty(key)){
            ConcurrentHashMap<Long,CacheValue> cache = CATCH.get(key);
            if (cache != null){
                Optional<Long> cacheTime = cache.keySet().stream().findFirst();
                if (cacheTime.isPresent()){
                    CacheValue cacheValue = cache.get(cacheTime.get());
                    long now = System.currentTimeMillis();
                    if ((now - cacheTime.get()) < (cacheValue.getValidTime() * 1000)){
                        return cacheValue.getValue();
                    }else {
                        //缓存失效
                        cache.clear();
                        CATCH.put(key,cache);
                    }
                }
            }
        }
        return null;
    }
}
 
开发者ID:DevopsJK,项目名称:SuitAgent,代码行数:29,代码来源:CacheByTimeUtil.java

示例3: clear

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
public void clear() {
    if (k1_k2V_map.size() > 0) {
        for (ConcurrentHashMap<K2, V> k2V_map : k1_k2V_map.values()) {
            k2V_map.clear();
        }
        k1_k2V_map.clear();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:DoubleKeyValueMap.java

示例4: setCache

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
/**
 * 设置缓存(指定缓存有效时间)
 * @param key
 * @param value
 * @param validTime
 */
public static void setCache(String key,Object value,int validTime) {
    synchronized (key.intern()){
        if (StringUtils.isNotEmpty(key) && value != null){
            ConcurrentHashMap<Long,CacheValue> cache = CATCH.get(key);
            if (cache == null){
                cache = new ConcurrentHashMap<>();
            }
            cache.clear();
            cache.put(System.currentTimeMillis(),new CacheValue(validTime,value));
            CATCH.put(key,cache);
        }
    }
}
 
开发者ID:DevopsJK,项目名称:SuitAgent,代码行数:20,代码来源:CacheByTimeUtil.java

示例5: disconnected

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
@Override
public void disconnected(ConnectionPool parent, PooledConnection con, boolean finalizing) {
    @SuppressWarnings("unchecked")
    ConcurrentHashMap<CacheKey,CachedStatement> statements =
        (ConcurrentHashMap<CacheKey,CachedStatement>)con.getAttributes().get(STATEMENT_CACHE_ATTR);

    if (statements!=null) {
        for (Map.Entry<CacheKey, CachedStatement> p : statements.entrySet()) {
            closeStatement(p.getValue());
        }
        statements.clear();
    }

    super.disconnected(parent, con, finalizing);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:16,代码来源:StatementCache.java

示例6: 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

示例7: removeCachedCalls

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
public void removeCachedCalls(String cacheName) {
    ConcurrentHashMap<UUID, CacheCallData> cachedCalls = mTaggedCacheCalls.get(cacheName);
    if (cachedCalls != null) cachedCalls.clear();
}
 
开发者ID:metarhia,项目名称:metacom-android,代码行数:5,代码来源:AndroidJSTPConnection.java

示例8: testClear

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
/**
 * clear removes all pairs
 */
public void testClear() {
    ConcurrentHashMap map = map5();
    map.clear();
    assertEquals(0, map.size());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:ConcurrentHashMapTest.java

示例9: process

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
@Override
public void process(ConcurrentHashMap<K, V> impl) {
    impl.clear();
}
 
开发者ID:pravega,项目名称:pravega-samples,代码行数:5,代码来源:SharedMap.java


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