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

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

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

ConcurrentHashMap.containsKey介绍

[英]Tests if the specified object is a key in this table.
[中]测试指定的对象是否是此表中的键。

代码示例

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

public void clearStats(long threadId) {
  if (cpuInfoConcurrentHashMap.containsKey(threadId)) {
    cpuInfoConcurrentHashMap.remove(threadId);
  }
}

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

List<FileStatus> files = input2FileStatus.get(fileName);
List<Path> paths = Utilities.convertStatusToPath(files);
ConcurrentHashMap<XLearningContainerId, ConcurrentHashMap<String, InputInfo>> containersFiles = new ConcurrentHashMap<>();
 ConcurrentHashMap<String, InputInfo> mapSplit;
 XLearningContainerId containerId = new XLearningContainerId(acquiredWorkerContainers.get(index).getId());
 if (containersFiles.containsKey(containerId)) {
  mapSplit = containersFiles.get(containerId);
 } else {
  mapSplit = new ConcurrentHashMap<>();
  containersFiles.put(containerId, mapSplit);
 if (mapSplit.containsKey(fileName)) {
  mapSplit.get(fileName).addPath(paths.get(i));
 } else {
  InputInfo inputInfo = new InputInfo();
  ps.add(paths.get(i));
  inputInfo.setPaths(ps);
  mapSplit.put(fileName, inputInfo);

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

if (challengeMap.get(m.tag) == null) {
    mySocket.send(requestPacket);
ConcurrentHashMap<Long, Long> tmpMap = addrChallengeMap.get(m.addr); 
if(tmpMap != null){
  Long tmpLong = tmpMap.get(m.tag);
  if (tmpLong != null) {
    newChallenge = tmpLong;
  tmpMap.put(m.tag, newChallenge);
          challengeMutex.put(m.tag, s);
          s.tryAcquire((long) timeout, TimeUnit.MILLISECONDS);
          myChallenge = challengeMap
              .containsKey(m.tag);
      double timeout = ackWait
          * java.lang.Math.pow(10, attempts);
      ackMutex.put(m.tag, s);
      s.tryAcquire((int) timeout, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
    challengeMap.remove(m.tag);
  challengeMap.remove(m.tag);
  sendqueue.offer(m);

代码示例来源:origin: igniterealtime/Openfire

if (MUTEX.containsKey(username)) {
  MUTEX.put(username, username);
  throw re;
} finally {
  MUTEX.remove(username);

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

public void createRemoteRegionReferenceLocally(ByteArrayWrapper key, RedisDataType type) {
 if (type == null || type == RedisDataType.REDIS_STRING || type == RedisDataType.REDIS_HLL)
  return;
 Region<?, ?> r = this.regions.get(key);
 if (r != null)
  return;
 if (!this.regions.containsKey(key)) {
  String stringKey = key.toString();
  Lock lock = this.locks.get(stringKey);
  if (lock == null) {
   this.locks.putIfAbsent(stringKey, new ReentrantLock());
   lock = this.locks.get(stringKey);
    this.regions.put(key, r);

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

if (challengeMap.get(m.tag) == null) {
    mySocket.send(requestPacket);
ConcurrentHashMap<Long, Long> tmpMap = addrChallengeMap.get(m.addr); 
if(tmpMap != null){
  Long tmpLong = tmpMap.get(m.tag);
  if (tmpLong != null) {
    newChallenge = tmpLong;
  tmpMap.put(m.tag, newChallenge);
          challengeMutex.put(m.tag, s);
          s.tryAcquire((long) timeout, TimeUnit.MILLISECONDS);
          myChallenge = challengeMap
              .containsKey(m.tag);
      double timeout = ackWait
          * java.lang.Math.pow(10, attempts);
      ackMutex.put(m.tag, s);
      s.tryAcquire((int) timeout, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
    challengeMap.remove(m.tag);
  challengeMap.remove(m.tag);
  sendqueue.offer(m);

代码示例来源:origin: ltsopensource/light-task-scheduler

/**
 * 添加channel
 */
public void offerChannel(ChannelWrapper channel) {
  String nodeGroup = channel.getNodeGroup();
  NodeType nodeType = channel.getNodeType();
  List<ChannelWrapper> channels = getChannels(nodeGroup, nodeType);
  if (channels == null) {
    channels = new ArrayList<ChannelWrapper>();
    if (nodeType == NodeType.JOB_CLIENT) {
      clientChannelMap.put(nodeGroup, channels);
    } else if (nodeType == NodeType.TASK_TRACKER) {
      taskTrackerChannelMap.put(nodeGroup, channels);
      // 如果在离线列表中,那么移除
      if (offlineTaskTrackerMap.containsKey(channel.getIdentity())) {
        offlineTaskTrackerMap.remove(channel.getIdentity());
      }
    }
    channels.add(channel);
    LOGGER.info("new connected channel={}", channel);
  } else {
    if (!channels.contains(channel)) {
      channels.add(channel);
      LOGGER.info("new connected channel={}", channel);
    }
  }
}

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

/**
 * Remove the value set for key.
 *
 * @param key key to remove
 */
public void remove(PropertyKey key) {
 // remove is a nop if the key doesn't already exist
 if (mUserProps.containsKey(key)) {
  mUserProps.remove(key);
 }
}

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

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

private TimeWindowStatisticsImpl getOrCreateEmptyStats(final long interval) {
  if (!EMPTY.containsKey(interval)) {
    EMPTY.putIfAbsent(interval, new TimeWindowStatisticsImpl(interval, 0, -1, -1, -1, 0));
  }
  return EMPTY.get(interval);
}

相关文章