當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。