本文整理了Java中java.util.concurrent.ConcurrentHashMap
类的一些代码示例,展示了ConcurrentHashMap
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ConcurrentHashMap
类的具体详情如下:
包路径:java.util.concurrent.ConcurrentHashMap
类名称:ConcurrentHashMap
[英]A plug-in replacement for JDK1.5 java.util.concurrent.ConcurrentHashMap. This version is based on org.cliffc.high_scale_lib.NonBlockingHashMap. This solution should be completely compatible, including the serialized forms and all multi-threaded ordering guarantees.
[中]JDK1的插件替代品。5爪哇。util。同时发生的ConcurrentHashMap。此版本基于org。克利夫。高标度库。非封锁地图。此解决方案应完全兼容,包括序列化表单和所有多线程订购保证。
代码示例来源:origin: google/guava
@Override
protected Map<String, String> create(Entry<String, String>[] entries) {
return populate(new ConcurrentHashMap<String, String>(), entries);
}
})
代码示例来源:origin: stanfordnlp/CoreNLP
@Override
public void addPatterns(String sentId, Map<Integer, Set<E>> patterns) {
if (!patternsForEachToken.containsKey(sentId))
patternsForEachToken.put(sentId, new ConcurrentHashMap<>());
patternsForEachToken.get(sentId).putAll(patterns);
}
代码示例来源:origin: apache/flink
@Override
public void updateKvStateLocationOracle(JobID jobId, @Nullable KvStateLocationOracle kvStateLocationOracle) {
if (kvStateLocationOracle == null) {
kvStateLocationOracles.remove(jobId);
} else {
kvStateLocationOracles.put(jobId, kvStateLocationOracle);
}
}
代码示例来源:origin: apache/incubator-druid
private boolean isTaskInPendingCompletionGroups(String taskId)
{
for (List<TaskGroup> taskGroups : pendingCompletionTaskGroups.values()) {
for (TaskGroup taskGroup : taskGroups) {
if (taskGroup.tasks.containsKey(taskId)) {
return true;
}
}
}
return false;
}
代码示例来源:origin: apache/incubator-dubbo
public static <T> ProviderInvokerWrapper<T> registerProvider(Invoker<T> invoker, URL registryUrl, URL providerUrl) {
ProviderInvokerWrapper<T> wrapperInvoker = new ProviderInvokerWrapper<>(invoker, registryUrl, providerUrl);
String serviceUniqueName = providerUrl.getServiceKey();
ConcurrentMap<Invoker, ProviderInvokerWrapper> invokers = providerInvokers.get(serviceUniqueName);
if (invokers == null) {
providerInvokers.putIfAbsent(serviceUniqueName, new ConcurrentHashMap<>());
invokers = providerInvokers.get(serviceUniqueName);
}
invokers.put(invoker, wrapperInvoker);
return wrapperInvoker;
}
代码示例来源:origin: Netflix/zuul
protected Deque<PooledConnection> getPoolForEventLoop(EventLoop eventLoop)
{
// We don't want to block under any circumstances, so can't use CHM.computeIfAbsent().
// Instead we accept the slight inefficiency of an unnecessary instantiation of a ConcurrentLinkedDeque.
Deque<PooledConnection> pool = connectionsPerEventLoop.get(eventLoop);
if (pool == null) {
pool = new ConcurrentLinkedDeque<>();
connectionsPerEventLoop.putIfAbsent(eventLoop, pool);
}
return pool;
}
代码示例来源:origin: Netflix/zuul
void putFilter(String sName, ZuulFilter filter, long lastModified)
{
List<ZuulFilter> list = hashFiltersByType.get(filter.filterType());
if (list != null) {
hashFiltersByType.remove(filter.filterType()); //rebuild this list
}
String nameAndType = filter.filterType() + ":" + filter.filterName();
filtersByNameAndType.put(nameAndType, filter);
filterRegistry.put(sName, filter);
filterClassLastModified.put(sName, lastModified);
}
代码示例来源:origin: apache/incubator-dubbo
public static Set<ProviderInvokerWrapper> getProviderInvoker(String serviceUniqueName) {
ConcurrentMap<Invoker, ProviderInvokerWrapper> invokers = providerInvokers.get(serviceUniqueName);
if (invokers == null) {
return Collections.emptySet();
}
return new HashSet<>(invokers.values());
}
代码示例来源:origin: apache/incubator-shardingsphere
@Override
public String getDataSource(final String name, final String masterDataSourceName, final List<String> slaveDataSourceNames) {
AtomicInteger count = COUNT_MAP.containsKey(name) ? COUNT_MAP.get(name) : new AtomicInteger(0);
COUNT_MAP.putIfAbsent(name, count);
count.compareAndSet(slaveDataSourceNames.size(), 0);
return slaveDataSourceNames.get(Math.abs(count.getAndIncrement()) % slaveDataSourceNames.size());
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public Object put(String key, Object value) {
if (value != null) {
return super.put(key, value);
}
else {
return remove(key);
}
}
代码示例来源:origin: stanfordnlp/CoreNLP
/**
* Increments the entry for this guess and gold by the given increment amount.
*/
public synchronized void add(U guess, U gold, int increment) {
Pair<U, U> pair = new Pair<>(guess, gold);
if (confTable.containsKey(pair)) {
confTable.put(pair, confTable.get(pair) + increment);
} else {
confTable.put(pair, increment);
}
}
代码示例来源:origin: xuxueli/xxl-job
private static int count(int jobId) {
// cache clear
if (System.currentTimeMillis() > CACHE_VALID_TIME) {
routeCountEachJob.clear();
CACHE_VALID_TIME = System.currentTimeMillis() + 1000*60*60*24;
}
// count++
Integer count = routeCountEachJob.get(jobId);
count = (count==null || count>1000000)?(new Random().nextInt(100)):++count; // 初始化时主动Random一次,缓解首次压力
routeCountEachJob.put(jobId, count);
return count;
}
代码示例来源:origin: apache/incubator-dubbo
private InvocationHandler buildInvocationHandler(String referencedBeanName, ReferenceBean referenceBean) {
ReferenceBeanInvocationHandler handler = localReferenceBeanInvocationHandlerCache.get(referencedBeanName);
if (handler == null) {
handler = new ReferenceBeanInvocationHandler(referenceBean);
}
if (applicationContext.containsBean(referencedBeanName)) { // Is local @Service Bean or not ?
// ReferenceBeanInvocationHandler's initialization has to wait for current local @Service Bean has been exported.
localReferenceBeanInvocationHandlerCache.put(referencedBeanName, handler);
} else {
// Remote Reference Bean should initialize immediately
handler.init();
}
return handler;
}
代码示例来源:origin: apache/incubator-druid
private void killTaskGroupForPartitions(Set<PartitionIdType> partitions, String reasonFormat, Object... args)
{
for (PartitionIdType partition : partitions) {
int taskGroupId = getTaskGroupIdForPartition(partition);
killTasksInGroup(activelyReadingTaskGroups.get(taskGroupId), reasonFormat, args);
partitionGroups.remove(taskGroupId);
activelyReadingTaskGroups.remove(taskGroupId);
}
}
代码示例来源:origin: google/guava
/**
* If {@code (key, value)} is currently in the map, this method removes it and returns true;
* otherwise, this method returns false.
*/
boolean remove(K key, long value) {
return map.remove(key, value);
}
代码示例来源:origin: prestodb/presto
private boolean isNodeShuttingDown(String nodeId)
{
Optional<NodeState> remoteNodeState = nodeStates.containsKey(nodeId)
? nodeStates.get(nodeId).getNodeState()
: Optional.empty();
return remoteNodeState.isPresent() && remoteNodeState.get() == SHUTTING_DOWN;
}
代码示例来源:origin: google/guava
/**
* Removes all of the mappings from this map. The map will be empty after this call returns.
*
* <p>This method is not atomic: the map may not be empty after returning if there were concurrent
* writes.
*/
public void clear() {
map.clear();
}
代码示例来源:origin: codecentric/spring-boot-admin
@Override
public Mono<Void> doNotify(InstanceEvent event, Instance instance) {
return delegate.notify(event).onErrorResume(error -> Mono.empty()).then(Mono.fromRunnable(() -> {
if (shouldEndReminder(event)) {
reminders.remove(event.getInstance());
} else if (shouldStartReminder(event)) {
reminders.putIfAbsent(event.getInstance(), new Reminder(event));
}
}));
}
代码示例来源: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: google/guava
/** Returns true if this map contains a mapping for the specified key. */
public boolean containsKey(Object key) {
return map.containsKey(key);
}
内容来源于网络,如有侵权,请联系作者删除!