本文整理了Java中java.util.concurrent.ConcurrentHashMap.computeIfAbsent()
方法的一些代码示例,展示了ConcurrentHashMap.computeIfAbsent()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ConcurrentHashMap.computeIfAbsent()
方法的具体详情如下:
包路径:java.util.concurrent.ConcurrentHashMap
类名称:ConcurrentHashMap
方法名:computeIfAbsent
暂无
代码示例来源:origin: neo4j/neo4j
private static Map<String, PropertyGetter> serialization( Class<? extends ObjectRepresentation> type )
{
Map<String, PropertyGetter> serialization = serializations.computeIfAbsent(
type, ObjectRepresentation::buildSerialization );
return serialization;
}
代码示例来源:origin: neo4j/neo4j
ThreadPool getThreadPool( Group group )
{
return pools.computeIfAbsent( group, poolBuilder );
}
代码示例来源:origin: stanfordnlp/CoreNLP
private synchronized void compileColonPatterns() {
if (colonsPat == null) {
colonsPat = new Pattern[colons.length];
for (int i = 0; i < colons.length; i++) {
Character colon = colons[i];
colonsPat[i] = patternMap.computeIfAbsent(WHITE + colon + WHITE, (s) -> Pattern.compile(s));
}
}
}
代码示例来源:origin: stanfordnlp/CoreNLP
private synchronized void compileColonsWhitePatterns(String numPat) {
if (colonsWhitePat == null) {
colonsWhitePat = new Pattern[colons.length];
for (int i = 0; i < colons.length; i++) {
Character colon = colons[i];
String pattern = "(" + numPat + ")" + WHITEPLUS + colon + WHITEPLUS + "(" + numPat + ")";
colonsWhitePat[i] = patternMap.computeIfAbsent(pattern, (s) -> Pattern.compile(s));
}
}
}
代码示例来源:origin: neo4j/neo4j
private T getLog( String name, Supplier<T> logSupplier )
{
return logCache.computeIfAbsent( name, s -> logSupplier.get() );
}
代码示例来源:origin: apache/incubator-druid
@VisibleForTesting
public void moveTaskGroupToPendingCompletion(int taskGroupId)
{
final TaskGroup taskGroup = activelyReadingTaskGroups.remove(taskGroupId);
if (taskGroup != null) {
pendingCompletionTaskGroups.computeIfAbsent(taskGroupId, k -> new CopyOnWriteArrayList<>()).add(taskGroup);
}
}
代码示例来源:origin: stanfordnlp/CoreNLP
private Pattern[] compilePunctuationPatterns() {
Pattern[] puncsPat = new Pattern[puncs.length];
for (int i = 0; i < puncs.length; i++) {
Character punc = puncs[i];
puncsPat[i] = patternMap.computeIfAbsent(getEscapedPuncPattern(punc), (s) -> Pattern.compile(s));
}
return puncsPat;
}
代码示例来源:origin: apache/storm
private LocalizedResource getUserArchive(String user, String key) {
assert user != null : "All user archives require a user present";
ConcurrentMap<String, LocalizedResource> keyToResource = userArchives.computeIfAbsent(user, (u) -> new ConcurrentHashMap<>());
return keyToResource.computeIfAbsent(key,
(k) -> new LocalizedResource(key, localBaseDir, true, fsOps, conf, user, metricsRegistry));
}
代码示例来源:origin: apache/storm
/**
* Go through all executors and time them out if needed.
* @param topoId the id of the topology to look at.
* @param taskTimeoutSecs the timeout to know if they are too old.
*/
public void timeoutOldHeartbeats(String topoId, Integer taskTimeoutSecs) {
Map<List<Integer>, ExecutorCache> topoCache = cache.computeIfAbsent(topoId, MAKE_MAP);
for (ExecutorCache ec : topoCache.values()) {
ec.updateTimeout(taskTimeoutSecs);
}
}
代码示例来源:origin: Netflix/zuul
@Override
public BasicNettyOrigin getOrigin(String name, String vip, String uri, SessionContext ctx) {
return originMappings.computeIfAbsent(name, n -> createOrigin(name, vip, uri, false, ctx));
}
代码示例来源:origin: Netflix/zuul
public Timing get(String name)
{
return additionalTimings.computeIfAbsent(name, (newName) -> new Timing(newName));
}
代码示例来源:origin: apache/storm
private LocalizedResource getUserFile(String user, String key) {
assert user != null : "All user archives require a user present";
ConcurrentMap<String, LocalizedResource> keyToResource = userFiles.computeIfAbsent(user, (u) -> new ConcurrentHashMap<>());
return keyToResource.computeIfAbsent(key,
(k) -> new LocalizedResource(key, localBaseDir, false, fsOps, conf, user, metricsRegistry));
}
代码示例来源:origin: prestodb/presto
@Override
public <R> R withLease(Function<LookupSourceLease, R> action)
{
lock.readLock().lock();
try {
LookupSource lookupSource = suppliedLookupSources.computeIfAbsent(this, k -> lookupSourceSupplier.getLookupSource());
LookupSourceLease lease = new SpillAwareLookupSourceLease(lookupSource, spillingInfo);
return action.apply(lease);
}
finally {
lock.readLock().unlock();
}
}
代码示例来源:origin: AsyncHttpClient/async-http-client
private boolean offer0(Channel channel, Object partitionKey, long now) {
ConcurrentLinkedDeque<IdleChannel> partition = partitions.get(partitionKey);
if (partition == null) {
partition = partitions.computeIfAbsent(partitionKey, pk -> new ConcurrentLinkedDeque<>());
}
return partition.offerFirst(new IdleChannel(channel, now));
}
代码示例来源:origin: ben-manes/caffeine
@Override
public @Nullable V putIfAbsent(K key, V value) {
requireNonNull(value);
boolean[] wasAbsent = new boolean[1];
V val = data.computeIfAbsent(key, k -> {
writer.write(key, value);
wasAbsent[0] = true;
return value;
});
return wasAbsent[0] ? null : val;
}
代码示例来源:origin: Netflix/zuul
@Override
public BasicNettyOrigin getOrigin(String name, String vip, String uri, SessionContext ctx) {
return originMappings.computeIfAbsent(name, n -> createOrigin(name, vip, uri, false, ctx));
}
代码示例来源:origin: Netflix/zuul
public Timing get(String name)
{
return additionalTimings.computeIfAbsent(name, (newName) -> new Timing(newName));
}
代码示例来源:origin: alibaba/Sentinel
@Override
public long addMachine(MachineInfo machineInfo) {
AppInfo appInfo = apps.computeIfAbsent(machineInfo.getApp(), app -> new AppInfo(app));
appInfo.addMachine(machineInfo);
return 1;
}
代码示例来源:origin: neo4j/neo4j
private void handleSubmission( BoltConnection connection )
{
activeWorkItems.computeIfAbsent( connection.id(),
key -> scheduleBatchOrHandleError( connection ).whenCompleteAsync( ( result, error ) -> handleCompletion( connection, result, error ),
forkJoinPool ) );
}
代码示例来源:origin: apache/storm
@VisibleForTesting
CompletableFuture<Void> requestDownloadBaseTopologyBlobs(PortAndAssignment pna, BlobChangingCallback cb) {
final String topologyId = pna.getToplogyId();
final LocallyCachedBlob topoJar = getTopoJar(topologyId, pna.getAssignment().get_owner());
topoJar.addReference(pna, cb);
final LocallyCachedBlob topoCode = getTopoCode(topologyId, pna.getAssignment().get_owner());
topoCode.addReference(pna, cb);
final LocallyCachedBlob topoConf = getTopoConf(topologyId, pna.getAssignment().get_owner());
topoConf.addReference(pna, cb);
return topologyBasicDownloaded.computeIfAbsent(topologyId,
(tid) -> downloadOrUpdate(topoJar, topoCode, topoConf));
}
内容来源于网络,如有侵权,请联系作者删除!