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

x33g5p2x  于2022-01-17 转载在 其他  
字(6.2k)|赞(0)|评价(0)|浏览(181)

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

ConcurrentHashMap.forEach介绍

暂无

代码示例

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

public void forEachEmitter(BiConsumer<URI, HttpPostEmitter> action)
{
 emitters.forEach(action);
}

代码示例来源:origin: ben-manes/caffeine

@Override
public void forEach(BiConsumer<? super K, ? super V> action) {
 data.forEach(action);
}

代码示例来源:origin: wildfly/wildfly

public void forEach(final BiConsumer<? super K, ? super V> action) {
  backingMap.forEach(action);
}

代码示例来源:origin: orbit/orbit

public void forEach(BiConsumer<K, V> callable) {
  this.observers.forEach(callable);
}

代码示例来源:origin: neo4j/neo4j

public InterruptedException shutDownAll()
  {
    pools.forEach( ( group, pool ) -> pool.cancelAllJobs() );
    pools.forEach( ( group, pool ) -> pool.shutDown() );
    return pools.values().stream()
          .map( ThreadPool::getShutdownException )
          .reduce( null, Exceptions::chain );
  }
}

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

@Override
public void resume() {
  consumers.forEach((name, consumer) -> consumer.resume());
}

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

@Override
public void pause() {
  consumers.forEach((name, consumer) -> consumer.pause());
}

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

/**
 * Clears all entries from the map. This is not threadsafe, and requires external synchronization
 * to prevent concurrent modifications to the cache.
 */
public void clear() {
 mMap.forEach((key, value) -> {
  onCacheUpdate(key, value.mValue);
  onRemove(key);
 });
 mMap.clear();
}

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

public synchronized void shutdown() {
  if (defaultCacheMonitorManager != null) {
    defaultCacheMonitorManager.stop();
  }
  ConcurrentHashMap<String, Cache> m = cacheManager;
  cacheManager = null;
  m.forEach((k, c) -> c.close());
  defaultCacheMonitorManager = null;
}

代码示例来源:origin: blynkkk/blynk-server

public void close() {
  System.out.println("Closing all sockets...");
  DefaultChannelGroup allChannels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
  userSession.forEach((userKey, session) -> {
    allChannels.addAll(session.appChannels);
    allChannels.addAll(session.hardwareChannels);
  });
  allChannels.close().awaitUninterruptibly();
}

代码示例来源:origin: ben-manes/caffeine

private void checkMap(UnboundedLocalCache<K, V> map, DescriptionBuilder desc) {
 if (map.isEmpty()) {
  desc.expectThat("empty map", map, emptyMap());
 }
 map.data.forEach((key, value) -> {
  desc.expectThat("non null key", key, is(not(nullValue())));
  desc.expectThat("non null value", value, is(not(nullValue())));
  if (value instanceof CompletableFuture<?>) {
   CompletableFuture<?> future = (CompletableFuture<?>) value;
   boolean success = future.isDone() && !future.isCompletedExceptionally();
   desc.expectThat("future is done", success, is(true));
   desc.expectThat("not null value", future.getNow(null), is(not(nullValue())));
  }
 });
}

代码示例来源:origin: com.github.ben-manes.caffeine/caffeine

@Override
public void forEach(BiConsumer<? super K, ? super V> action) {
 data.forEach(action);
}

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

recoveryBallotBoxes.forEach((nearNodeId, ballotBox) -> {

代码示例来源:origin: biezhi/learn-java8

private static void testForEach() {
    ConcurrentHashMap<String, String> map = new ConcurrentHashMap<>();
    map.putIfAbsent("foo", "bar");
    map.putIfAbsent("han", "solo");
    map.putIfAbsent("r2", "d2");
    map.putIfAbsent("c3", "p0");

    map.forEach(1, (key, value) -> System.out.printf("key: %s; value: %s; thread: %s\n", key, value, Thread.currentThread().getName()));
//        map.forEach(5, (key, value) -> System.out.printf("key: %s; value: %s; thread: %s\n", key, value, Thread.currentThread().getName()));

    System.out.println(map.mappingCount());
  }

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

private void executeTriggers(TransactionData txData, String phase) {
  if (triggers.containsKey("")) updateTriggers(null,null);
  GraphDatabaseService db = properties.getGraphDatabase();
  Map<String,String> exceptions = new LinkedHashMap<>();
  Map<String, Object> params = txDataParams(txData, phase);
  triggers.forEach((name, data) -> {
    if( data.get("paused").equals(false)) {
      if( data.get( "params" ) != null)
      {
        params.putAll( (Map<String,Object>) data.get( "params" ) );
      }
      try (Transaction tx = db.beginTx()) {
        Map<String,Object> selector = (Map<String, Object>) data.get("selector");
        if (when(selector, phase)) {
          params.put("trigger", name);
          Result result = db.execute((String) data.get("kernelTransaction"), params);
          Iterators.count(result);
          result.close();
        }
        tx.success();
      } catch(Exception e) {
        log.warn("Error executing trigger "+name+" in phase "+phase,e);
        exceptions.put(name, e.getMessage());
      }
    }
  });
  if (!exceptions.isEmpty()) {
    throw new RuntimeException("Error executing triggers "+exceptions.toString());
  }
}

代码示例来源:origin: arun-gupta/microservices

private void writeMap() {
//        Files.write(path, "".getBytes(), StandardOpenOption.TRUNCATE_EXISTING);
    serviceNameToURI.forEach((k, v) -> {
      try {
        Files.write(path, (k + "=" + v + "\n").getBytes(), StandardOpenOption.APPEND);
      } catch (IOException ex) {
        throw new RuntimeException(ex);
      }
    });
  }
}

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

/*package-testing*/ static void clearLocksProcessState() { 
  synchronized(sync) {
    try { 
      locks.forEach((path,lock)->lock.free());
      locks.clear(); 
    }
    catch (Exception ex) {
      // Shouldn't happen - trace and then ignore. 
      ex.printStackTrace();
    }
  }
}

代码示例来源:origin: Netflix/spectator

private void updateMeters() {
 counters.forEach((id, c) -> c.set(newCounter(id)));
 distSummaries.forEach((id, d) -> d.set(newDistributionSummary(id)));
 timers.forEach((id, t) -> t.set(newTimer(id)));
 gauges.forEach((id, g) -> g.set(newGauge(id)));
}

代码示例来源:origin: net.oschina.j2cache/j2cache-core

@Override
public Collection<CacheChannel.Region> regions() {
  Collection<CacheChannel.Region> regions = new ArrayList<>();
  caches.forEach((k,c) -> regions.add(new CacheChannel.Region(k, c.size(), c.ttl())));
  return regions;
}

代码示例来源:origin: net.oschina.j2cache/j2cache-core

@Override
public Collection<CacheChannel.Region> regions() {
  Collection<CacheChannel.Region> regions = new ArrayList<>();
  caches.forEach((k,c) -> regions.add(new CacheChannel.Region(k, c.size(), c.ttl())));
  return regions;
}

相关文章