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


Java ConcurrentMap类代码示例

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


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

示例1: doInTransaction

import java.util.concurrent.ConcurrentMap; //导入依赖的package包/类
void doInTransaction(Runnable dbWork) {
    ConcurrentMap<String, String> newStorage = new ConcurrentHashMap<String, String>();
    newStorage.putAll(storage);
    workingStorage.set(newStorage);

    SQLiteDatabase mDb = openDB();
    workingDB.set(mDb);

    List<String> changedKeys = new ArrayList<String>();
    workingChangedKeys.set(changedKeys);

    mDb.beginTransaction();
    try {
        dbWork.run();
        mDb.setTransactionSuccessful();
        storage = newStorage;
    } finally {
        workingDB.remove();
        workingStorage.remove();
        workingChangedKeys.remove();
        mDb.endTransaction();
        mDb.close();
    }
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:25,代码来源:Storage.java

示例2: getTimeSeries

import java.util.concurrent.ConcurrentMap; //导入依赖的package包/类
private <P extends AbstractPoint, C extends ArrayChunk<P, C>, T extends TimeSeries<P, T>>
    List<T> getTimeSeries(String nodeId, Set<String> timeSeriesNames, int version,
                          ConcurrentMap<TimeSeriesChunkKey, C> map, BiFunction<TimeSeriesMetadata, List<C>, T> constr) {
    UUID nodeUuid = checkNodeId(nodeId);
    Objects.requireNonNull(timeSeriesNames);
    TimeSeriesIndex.checkVersion(version);
    Objects.requireNonNull(map);
    Objects.requireNonNull(constr);
    List<T> timeSeriesList = new ArrayList<>();
    for (String timeSeriesName : timeSeriesNames) {
        TimeSeriesMetadata metadata = timeSeriesMetadataMap.get(new NamedLink(nodeUuid, timeSeriesName));
        if (metadata == null) {
            throw createTimeSeriesNotFoundAtNode(timeSeriesName, nodeUuid);
        }
        List<C> chunks = getChunks(nodeUuid, version, timeSeriesName, metadata, map);
        if (!chunks.isEmpty()) {
            timeSeriesList.add(constr.apply(metadata, chunks));
        }
    }
    return timeSeriesList;
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:22,代码来源:MapDbAppStorage.java

示例3: findServicesByApplication

import java.util.concurrent.ConcurrentMap; //导入依赖的package包/类
public List<String> findServicesByApplication(String application) {
    List<String> ret = new ArrayList<String>();
    ConcurrentMap<String, Map<Long, URL>> consumerUrls = getRegistryCache().get(Constants.CONSUMERS_CATEGORY);
    if(consumerUrls == null || application == null || application.length() == 0) return ret;
    
    for(Map.Entry<String, Map<Long, URL>> e1 : consumerUrls.entrySet()) {
        Map<Long, URL> value = e1.getValue();
        for(Map.Entry<Long, URL> e2 : value.entrySet()) {
            URL u = e2.getValue();
            if(application.equals(u.getParameter(Constants.APPLICATION_KEY))) {
                ret.add(e1.getKey());
                break;
            }
        }
    }
    
    return ret;
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:19,代码来源:ConsumerServiceImpl.java

示例4: mapZip

import java.util.concurrent.ConcurrentMap; //导入依赖的package包/类
private static ConcurrentMap<Object, JsonObject> mapZip(
        final JsonArray sources,
        final String field
) {
    final ConcurrentMap<Object, JsonObject> resultMap =
            new ConcurrentHashMap<>();
    Observable.fromIterable(sources)
            .map(item -> (JsonObject) item)
            .subscribe(item -> {
                if (item.containsKey(field)) {
                    final Object value = item.getValue(field);
                    if (null != value) {
                        resultMap.put(value, item);
                    }
                }
            });
    return resultMap;
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:19,代码来源:Dual.java

示例5: testSerializationWithMapMaker_preservesIdentityKeyEquivalence

import java.util.concurrent.ConcurrentMap; //导入依赖的package包/类
public void testSerializationWithMapMaker_preservesIdentityKeyEquivalence() {
  ConcurrentMap<String, AtomicInteger> map =
      new MapMaker().keyEquivalence(Equivalence.identity()).makeMap();

  ConcurrentHashMultiset<String> multiset = ConcurrentHashMultiset.create(map);
  multiset = reserializeAndAssert(multiset);

  String s1 = new String("a");
  String s2 = new String("a");
  assertEquals(s1, s2); // Stating the obvious.
  assertTrue(s1 != s2); // Stating the obvious.

  multiset.add(s1);
  assertTrue(multiset.contains(s1));
  assertFalse(multiset.contains(s2));
  assertEquals(1, multiset.count(s1));
  assertEquals(0, multiset.count(s2));
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:19,代码来源:ConcurrentHashMultisetTest.java

示例6: putAllCollections

import java.util.concurrent.ConcurrentMap; //导入依赖的package包/类
static void putAllCollections(Map<Class<?>, IntFunction<?>> map, Map<Class<?>, Function<?, ?>> unmodMap)
{
    safePut(map, ArrayList.class, ArrayList::new);
    safePut(map, HashSet.class, LinkedHashSet::new);
    safePut(map, Properties.class, x -> new Properties());
    safePut(map, Hashtable.class, Hashtable::new);

    safePut(map, Collection.class, ArrayList::new);
    safePut(map, Set.class, LinkedHashSet::new);
    safePut(map, List.class, ArrayList::new);
    safePut(map, SortedSet.class, x -> new TreeSet<>());
    safePut(map, Queue.class, x -> new ConcurrentLinkedQueue<>());
    safePut(map, Deque.class, x -> new ConcurrentLinkedDeque<>());
    safePut(map, BlockingQueue.class, x -> new LinkedBlockingQueue<>());
    safePut(map, BlockingDeque.class, x -> new LinkedBlockingDeque<>());


    safePut(map, HashMap.class, LinkedHashMap::new);
    safePut(map, LinkedHashMap.class, LinkedHashMap::new);
    safePut(map, ConcurrentHashMap.class, ConcurrentHashMap::new);

    safePut(map, Map.class, LinkedHashMap::new);
    safePut(map, ConcurrentMap.class, x -> new ConcurrentSkipListMap<>());
    safePut(map, ConcurrentNavigableMap.class, x -> new ConcurrentSkipListMap<>());
    safePut(map, SortedMap.class, i -> new TreeMap<>());
}
 
开发者ID:GotoFinal,项目名称:diorite-configs-java8,代码行数:27,代码来源:YamlCollectionCreator.java

示例7: _getEntry

import java.util.concurrent.ConcurrentMap; //导入依赖的package包/类
private Entry _getEntry(
  StyleContext context,
  StyleSheetDocument document,
  ConcurrentMap<Key, Future<Entry>> cache,
  Key key,
  boolean checkModified
  )
{
  Future<Entry> f = cache.get(key);
  Entry entry = _getEntryFromFuture(context, document, cache, key, f);
  if ((entry != null) && !_validateEntry(entry, checkModified))
  {
    // atomically remove the key from the cache if it currently points to the entry
    cache.remove(key, f);
    entry = null;
  }
  
  return entry;
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:20,代码来源:FileSystemStyleCache.java

示例8: findApplicationsByServiceName

import java.util.concurrent.ConcurrentMap; //导入依赖的package包/类
public List<String> findApplicationsByServiceName(String service) {
    List<String> ret = new ArrayList<String>();
    ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
    if(null == providerUrls) return ret;
    
    Map<Long, URL> value = providerUrls.get(service);
    if(value == null){
    	return ret;
    }
    for(Map.Entry<Long, URL> e2 : value.entrySet()) {
        URL u = e2.getValue();
        String app = u.getParameter(Constants.APPLICATION_KEY);
        if(app != null) ret.add(app);
    }
    
    return ret;
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:18,代码来源:ProviderServiceImpl.java

示例9: getAuthnRequestAuthnRequestFromRelyingPartyTransformer

import java.util.concurrent.ConcurrentMap; //导入依赖的package包/类
@Provides
private AuthnRequestToIdaRequestFromRelyingPartyTransformer getAuthnRequestAuthnRequestFromRelyingPartyTransformer(
        @Named("authnRequestKeyStore") SigningKeyStore signingKeyStore,
        IdaKeyStore decryptionKeyStore,
        SamlConfiguration samlConfiguration,
        ConcurrentMap<AuthnRequestIdKey, DateTime> duplicateIds,
        SamlDuplicateRequestValidationConfiguration duplicateRequestValidationConfiguration,
        SamlAuthnRequestValidityDurationConfiguration authnRequestValidityDurationConfiguration
) {
    return hubTransformersFactory.getAuthnRequestToAuthnRequestFromTransactionTransformer(
            samlConfiguration.getExpectedDestinationHost(),
            signingKeyStore,
            decryptionKeyStore,
            duplicateIds,
            duplicateRequestValidationConfiguration,
            authnRequestValidityDurationConfiguration
    );
}
 
开发者ID:alphagov,项目名称:verify-hub,代码行数:19,代码来源:SamlEngineModule.java

示例10: calculateServices

import java.util.concurrent.ConcurrentMap; //导入依赖的package包/类
private ConcurrentMap<Flag, Set<String>> calculateServices(
        final ConcurrentMap<String, Record> services) {
    // Read new services.
    final Set<String> populated = new HashSet<>();
    Observable.fromIterable(services.keySet())
            .subscribe(populated::add);

    // Existed = Yes, Populated = No
    final Set<String> deleted = new HashSet<>(REGISTRITIONS.keySet());
    deleted.removeAll(populated);

    // Existed = Yes, Populated = Yes
    final Set<String> updated = new HashSet<>(REGISTRITIONS.keySet());
    updated.retainAll(populated);

    // Existed = No, Populated = Yes
    final Set<String> added = new HashSet<>(populated);
    added.removeAll(REGISTRITIONS.keySet());

    // Mapping data
    final ConcurrentMap<Flag, Set<String>> result = new ConcurrentHashMap<>();
    result.put(Flag.DELETE, deleted);
    result.put(Flag.NEW, added);
    result.put(Flag.UPDATE, updated);
    return result;
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:27,代码来源:ZeroApiWorker.java

示例11: findApplicationsByServiceName

import java.util.concurrent.ConcurrentMap; //导入依赖的package包/类
public List<String> findApplicationsByServiceName(String service) {
    List<String> ret = new ArrayList<String>();
    ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
    if (null == providerUrls) return ret;

    Map<Long, URL> value = providerUrls.get(service);
    if (value == null) {
        return ret;
    }
    for (Map.Entry<Long, URL> e2 : value.entrySet()) {
        URL u = e2.getValue();
        String app = u.getParameter(Constants.APPLICATION_KEY);
        if (app != null) ret.add(app);
    }

    return ret;
}
 
开发者ID:l1325169021,项目名称:github-test,代码行数:18,代码来源:ProviderServiceImpl.java

示例12: testReplace

import java.util.concurrent.ConcurrentMap; //导入依赖的package包/类
public void testReplace()
{
  ConcurrentMap<String, Object> cache = createMap();
  _putTwo(cache);
  Object val = cache.replace(C_STR, ONE);
  assertNull(val);
  assertEquals("Replace operation did not work as expected.", 2, cache.size());
  assertEquals(ONE, cache.get(A_STR));
  assertEquals(TWO, cache.get(B_STR));

  val = cache.replace(A_STR, "aaaString");
  assertEquals(ONE, val);
  assertEquals("Replace operation did not work as expected.", 2, cache.size());
  assertEquals("aaaString", cache.get(A_STR));

  boolean bool = cache.replace(B_STR, "bb", "newValue");
  assertFalse(bool);
  assertEquals("Replace operation did not work as expected.", 2, cache.size());
  assertEquals(TWO, cache.get(B_STR));

  bool = cache.replace(B_STR, TWO, "newValue");
  assertTrue(bool);
  assertEquals("Replace operation did not work as expected.", 2, cache.size());
  assertEquals("newValue", cache.get(B_STR));
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:26,代码来源:ConcurrentMapTestCase.java

示例13: testSingleReplace_SingleInstance

import java.util.concurrent.ConcurrentMap; //导入依赖的package包/类
@Test
public void testSingleReplace_SingleInstance() throws InterruptedException {
    final String name = "testSingleReplace_SingleInstance";

    ConcurrentMap<String, String> map = BaseTest.createInstance().getMap(name);
    map.put("1", "0");

    testSingleInstanceConcurrency(100, r -> {
        ConcurrentMap<String, String> map1 = r.getMap(name);
        map1.replace("1", "3");
    });

    ConcurrentMap<String, String> testMap = BaseTest.createInstance().getMap(name);
    Assert.assertEquals("3", testMap.get("1"));

    assertMapSize(1, name);
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:18,代码来源:RedissonConcurrentMapTest.java

示例14: testSinglePutIfAbsent_SingleInstance

import java.util.concurrent.ConcurrentMap; //导入依赖的package包/类
@Test
public void testSinglePutIfAbsent_SingleInstance() throws InterruptedException {
    final String name = "testSinglePutIfAbsent_SingleInstance";

    ConcurrentMap<String, String> map = BaseTest.createInstance().getMap(name);
    map.putIfAbsent("1", "0");
    testSingleInstanceConcurrency(100, r -> {
        ConcurrentMap<String, String> map1 = r.getMap(name);
        map1.putIfAbsent("1", "1");
    });

    ConcurrentMap<String, String> testMap = BaseTest.createInstance().getMap(name);
    Assert.assertEquals("0", testMap.get("1"));

    assertMapSize(1, name);
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:17,代码来源:RedissonConcurrentMapTest.java

示例15: _getProviders

import java.util.concurrent.ConcurrentMap; //导入依赖的package包/类
private static ConcurrentMap<ProviderKey, StyleProvider> _getProviders()
{
  ConcurrentMap<String, Object> appMap = 
    RequestContext.getCurrentInstance().getApplicationScopedConcurrentMap();

  ConcurrentMap<ProviderKey, StyleProvider> styleProviders =
    (ConcurrentMap<ProviderKey, StyleProvider>)appMap.get(_SKIN_PROVIDERS_KEY);

  if (styleProviders == null)
  {
    styleProviders = _createProvidersCache();

    ConcurrentMap<ProviderKey, StyleProvider> oldStyleProviders =
      (ConcurrentMap<ProviderKey, StyleProvider>)appMap.putIfAbsent(_SKIN_PROVIDERS_KEY, styleProviders);

    if (oldStyleProviders != null)
      styleProviders = oldStyleProviders;
  }

  return styleProviders;
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:22,代码来源:SkinStyleProvider.java


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