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

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

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

ConcurrentHashMap.remove介绍

[英]Removes the key (and its corresponding value) from this map. This method does nothing if the key is not in the map.
[中]从此映射中删除键(及其对应的值)。如果键不在映射中,则此方法不执行任何操作。

代码示例

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

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

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

private void removeFromCacheForServerToConstructedCQName(final String cqName,
  ClientProxyMembershipID clientProxyMembershipID) {
 ConcurrentHashMap<ClientProxyMembershipID, String> cache = serverCqNameCache.get(cqName);
 if (cache != null) {
  cache.remove(clientProxyMembershipID);
  if (cache.size() == 0) {
   serverCqNameCache.remove(cqName);
  }
 }
}

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

while(true) {
  totalQuery.incrementAndGet();
  Object value = core.get(key);
    core.put(key,new SoftReference<T>(t));
  else
    core.remove(key);

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

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

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

public void registerRegularForm(String fontNameAsInFontTablePart, PhysicalFont pfRegular) {
  if (pfRegular == null) {
    regularForms.remove(fontNameAsInFontTablePart);
  } else {
    regularForms.put(fontNameAsInFontTablePart, pfRegular);
  }
}

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

@Override
public void rename(String source, String dest) throws IOException {
 ensureOpen();
 FileEntry file = files.get(source);
 if (file == null) {
  throw new NoSuchFileException(source);
 }
 if (files.putIfAbsent(dest, file) != null) {
  throw new FileAlreadyExistsException(dest);
 }
 if (!files.remove(source, file)) {
  throw new IllegalStateException("File was unexpectedly replaced: " + source);
 }
 files.remove(source);
}

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

/**
 * @param nodeId Node ID.
 * @param qryTrackerId Query tracker Id.
 */
void onQueryDone(UUID nodeId, long qryTrackerId) {
  if (qryTrackerId == MVCC_TRACKER_ID_NA)
    return;
  synchronized (this) {
    Set<Long> nodeTrackers = activeQueries.get(nodeId);
    if (nodeTrackers == null || !nodeTrackers.remove(qryTrackerId)) {
      Set<Long> nodeAcks = rcvdAcks.get(nodeId);
      if (nodeAcks == null)
        rcvdAcks.put(nodeId, nodeAcks = new HashSet<>());
      // We received qry done ack before the active qry message. Need to save it.
      nodeAcks.add(qryTrackerId);
    }
    if (nodeTrackers != null && nodeTrackers.isEmpty())
      activeQueries.remove(nodeId);
    if (initDone && !prevQueriesDone)
      prevQueriesDone = activeQueries.isEmpty() && rcvdAcks.isEmpty();
  }
}

代码示例来源:origin: plutext/docx4j

public void registerBoldItalicForm(String fontNameAsInFontTablePart, PhysicalFont pfBoldItalic) {
  if (pfBoldItalic == null) {
    boldItalicForms.remove(fontNameAsInFontTablePart);
  } else {
    boldItalicForms.put(fontNameAsInFontTablePart, pfBoldItalic);
  }
}

代码示例来源:origin: thinkaurelius/titan

if (!locks.containsKey(kc)) {
  log.error("Local unlock failed: no locks found for {}", kc);
  return false;
AuditRecord<T> holder = locks.get(kc);
boolean removed = locks.remove(kc, unlocker);

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

private <T> LlapBufferOrBuffers putInternal(T key, ByteBuffer tailBuffer, String tag, AtomicBoolean isStopped) {
 LlapBufferOrBuffers result = null;
 while (true) { // Overwhelmingly executes once, or maybe twice (replacing stale value).
  LlapBufferOrBuffers oldVal = metadata.get(key);
  if (oldVal == null) {
   result = wrapBb(result, key, tailBuffer, tag, isStopped);
   oldVal = metadata.putIfAbsent(key, result);
   if (oldVal == null) {
    cacheInPolicy(result); // Cached successfully, add to policy.
    return result;
   }
  }
  if (lockOldVal(key, result, oldVal)) {
   return oldVal;
  }
  // We found some old value but couldn't incRef it; remove it.
  metadata.remove(key, oldVal);
 }
}

相关文章