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

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

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

ConcurrentHashMap.put介绍

[英]Maps the specified key to the specified value in this table. Neither the key nor the value can be null.

The value can be retrieved by calling the get method with a key that is equal to the original key.
[中]将指定的键映射到此表中的指定值。键和值都不能为null。
可以通过使用与原始键相等的键调用get方法来检索该值。

代码示例

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

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

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

public void addInstructionSet(String expressName, InstructionSet set)
    throws Exception {
  synchronized (expressInstructionSetCache) {
    if (expressInstructionSetCache.containsKey(expressName)) {
      throw new Exception("表达式定义重复:" + expressName);
    }
    expressInstructionSetCache.put(expressName, set);
  }
}

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

public void registerBoldForm(String fontNameAsInFontTablePart, PhysicalFont pfBold) {
  if (pfBold == null) {
    boldForms.remove(fontNameAsInFontTablePart);
  } else {
    boldForms.put(fontNameAsInFontTablePart, pfBold);
  }
}

代码示例来源:origin: org.apache.zookeeper/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: alibaba/nacos

public void addTask(Datum datum, ApplyAction action) {
  if (services.containsKey(datum.key) && action == ApplyAction.CHANGE) {
    return;
  }
  if (action == ApplyAction.CHANGE) {
    services.put(datum.key, StringUtils.EMPTY);
  }
  tasks.add(Pair.with(datum, action));
}

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

public void registerItalicForm(String fontNameAsInFontTablePart, PhysicalFont pfItalic) {
  if (pfItalic == null) {
    italicForms.remove(fontNameAsInFontTablePart);
  } else {
    italicForms.put(fontNameAsInFontTablePart, pfItalic);
  }
}

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

/**
 * Puts the key value pair specified by users.
 *
 * @param key key to put
 * @param value value to put
 * @param source the source of this value for the key
 */
protected void put(PropertyKey key, String value, Source source) {
 if (!mUserProps.containsKey(key) || source.compareTo(getSource(key)) >= 0) {
  mUserProps.put(key, Optional.ofNullable(value));
  mSources.put(key, source);
 }
}

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

/**
 * Generates and returns an internal id to track the FileOutputStream corresponding to individual
 * MediaMuxer instances.
 */
@Implementation
protected static long nativeSetup(@NonNull FileDescriptor fd, int format) throws IOException {
 FileOutputStream outputStream = fdToStream.get(fd);
 long potentialKey;
 do {
  potentialKey = random.nextLong();
 } while (potentialKey == 0 || outputStreams.putIfAbsent(potentialKey, outputStream) != null);
 nextTrackIndices.put(potentialKey, new AtomicInteger(0));
 return potentialKey;
}

代码示例来源: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: 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);
}

相关文章