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

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

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

ConcurrentHashMap.get介绍

[英]Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

More formally, if this map contains a mapping from a key k to a value v such that key.equals(k), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)
[中]返回指定键映射到的值,如果此映射不包含该键的映射,则返回null。
更正式地说,如果此映射包含从键k到值v的映射,则该键为。等于(k),则此方法返回v;否则返回null。(最多可以有一个这样的映射。)

代码示例

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

private ConcurrentLinkedQueue<OutstandingRequest> getQueue(String function) {
  if (function == null) {
    throw new IllegalArgumentException("The function for a request cannot be null");
  }
  ConcurrentLinkedQueue<OutstandingRequest> queue = _queues.get(function);
  if (queue == null) {
    _queues.putIfAbsent(function, new ConcurrentLinkedQueue<>());
    queue = _queues.get(function);
  }
  return queue;
}

代码示例来源:origin: jenkinsci/jenkins

public V get(K key) {
  V v = store.get(key);
  if(v!=null)     return v;
  // TODO: if we want to, we can avoid locking altogether by putting a sentinel value
  // that represents "the value is being computed". FingerprintMap does this.
  synchronized (this) {
    v = store.get(key);
    if(v!=null)     return v;
    v = compute(key);
    store.put(key,v);
    return v;
  }
}

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

public MemoryMapStateBacking(String id) {
  if (!_dbs.containsKey(id)) {
    _dbs.put(id, new HashMap());
  }
  this.db = (Map<List<Object>, T>) _dbs.get(id);
}

代码示例来源:origin: north2016/T-MVP

public OkBus unRegister(int tag) {
  if (mEventList.get(tag) != null)
    mEventList.remove(tag);
  return this;
}

代码示例来源: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: apache/zookeeper

boolean saveChallenge(long tag, long challenge) {
  Semaphore s = challengeMutex.get(tag);
  if (s != null) {
      synchronized (Messenger.this) {
        challengeMap.put(tag, challenge);
        challengeMutex.remove(tag);
      }
  
      s.release();
  } else {
    LOG.error("No challenge mutex object");
  }
  
  return true;
}

代码示例来源:origin: stanfordnlp/CoreNLP

@Override
public Map<Integer, Set<E>> getPatternsForAllTokens(String sentId) {
 return (Map<Integer, Set<E>>)(patternsForEachToken.containsKey(sentId) ? patternsForEachToken.get(sentId) : Collections.emptyMap());
}

代码示例来源:origin: weibocom/motan

private void addCommandListener(URL url, CommandListener commandListener) {
  String group = url.getGroup();
  ConcurrentHashMap<URL, CommandListener> map = commandListeners.get(group);
  if (map == null) {
    commandListeners.putIfAbsent(group, new ConcurrentHashMap<URL, CommandListener>());
    map = commandListeners.get(group);
  }
  synchronized (map) {
    map.put(url, commandListener);
  }
}

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

public void addError(long offset, int length, long baseOffset) {
 Long key = Long.valueOf(offset + baseOffset);
 Integer existingLength = cache.get(key);
 if (existingLength != null && existingLength >= length) return;
 Integer value = Integer.valueOf(length);
 while (true) {
  existingLength = cache.putIfAbsent(key, value);
  if (existingLength == null || existingLength >= length) return;
  cache.remove(key, existingLength);
 }
}

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

/**
 * Helper method to have a single point of deletion in the queued flows
 */
public void dequeue(final int executionId) {
 if (this.queuedFlowMap.containsKey(executionId)) {
  this.queuedFlowList.remove(this.queuedFlowMap.get(executionId));
  this.queuedFlowMap.remove(executionId);
 }
}

代码示例来源: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/zookeeper

/**
 * Removes element from the queue.
 * @param elem  element to remove
 * @return      time at which the element was set to expire, or null if
 *              it wasn't present
 */
public Long remove(E elem) {
  Long expiryTime = elemMap.remove(elem);
  if (expiryTime != null) {
    Set<E> set = expiryMap.get(expiryTime);
    if (set != null) {
      set.remove(elem);
      // We don't need to worry about removing empty sets,
      // they'll eventually be removed when they expire.
    }
  }
  return expiryTime;
}

代码示例来源: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: 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: thinkaurelius/titan

@Override
public KeyColumnValueStore openDatabase(final String name, StoreMetaData.Container metaData) throws BackendException {
  if (!stores.containsKey(name)) {
    stores.putIfAbsent(name, new InMemoryKeyColumnValueStore(name));
  }
  KeyColumnValueStore store = stores.get(name);
  Preconditions.checkNotNull(store);
  return store;
}

代码示例来源: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: 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: weibocom/motan

private void addServiceListener(URL url, ServiceListener serviceListener) {
  String service = ConsulUtils.getUrlClusterInfo(url);
  ConcurrentHashMap<URL, ServiceListener> map = serviceListeners.get(service);
  if (map == null) {
    serviceListeners.putIfAbsent(service, new ConcurrentHashMap<URL, ServiceListener>());
    map = serviceListeners.get(service);
  }
  synchronized (map) {
    map.put(url, serviceListener);
  }
}

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

/**
 * Remove the NonceKey if the procedure was not submitted to the executor.
 * @param nonceKey A unique identifier for this operation from the client or process.
 */
public void unregisterNonceIfProcedureWasNotSubmitted(final NonceKey nonceKey) {
 if (nonceKey == null) return;
 final Long procId = nonceKeysToProcIdsMap.get(nonceKey);
 if (procId == null) return;
 // if the procedure was not submitted, remove the nonce
 if (!(procedures.containsKey(procId) || completed.containsKey(procId))) {
  nonceKeysToProcIdsMap.remove(nonceKey);
 }
}

代码示例来源:origin: spring-projects/spring-security-oauth

private void addToCollection(ConcurrentHashMap<String, Collection<OAuth2AccessToken>> store, String key,
    OAuth2AccessToken token) {
  if (!store.containsKey(key)) {
    synchronized (store) {
      if (!store.containsKey(key)) {
        store.put(key, new HashSet<OAuth2AccessToken>());
      }
    }
  }
  store.get(key).add(token);
}

相关文章