本文整理了Java中java.util.concurrent.ConcurrentHashMap.replace()
方法的一些代码示例,展示了ConcurrentHashMap.replace()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ConcurrentHashMap.replace()
方法的具体详情如下:
包路径:java.util.concurrent.ConcurrentHashMap
类名称:ConcurrentHashMap
方法名:replace
暂无
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public synchronized boolean replace(K key, V oldVal, V newVal) {
return super.replace(key, oldVal, newVal);
}
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public synchronized V replace(K key, V val) {
return super.replace(key, val);
}
代码示例来源:origin: wildfly/wildfly
public boolean replace(final K key, final V oldValue, final V newValue) {
return backingMap.replace(key, oldValue, newValue);
}
代码示例来源:origin: wildfly/wildfly
public V replace(final K key, final V value) {
return backingMap.replace(key, value);
}
代码示例来源:origin: google/guava
/**
* If {@code (key, expectedOldValue)} is currently in the map, this method replaces {@code
* expectedOldValue} with {@code newValue} and returns true; otherwise, this method returns false.
*
* <p>If {@code expectedOldValue} is zero, this method will succeed if {@code (key, zero)} is
* currently in the map, or if {@code key} is not in the map at all.
*/
boolean replace(K key, long expectedOldValue, long newValue) {
if (expectedOldValue == 0L) {
return putIfAbsent(key, newValue) == 0L;
} else {
return map.replace(key, expectedOldValue, newValue);
}
}
}
代码示例来源:origin: apache/hive
void updateTaskAttempt(TezTaskAttemptID attemptId, boolean isGuaranteed) {
Boolean oldVal = tasks.replace(attemptId, isGuaranteed);
if (oldVal == null) {
LOG.warn("Task " + attemptId + " is no longer registered");
tasks.remove(attemptId);
}
}
代码示例来源:origin: prestodb/presto
/**
* If {@code (key, expectedOldValue)} is currently in the map, this method replaces {@code
* expectedOldValue} with {@code newValue} and returns true; otherwise, this method returns false.
*
* <p>If {@code expectedOldValue} is zero, this method will succeed if {@code (key, zero)} is
* currently in the map, or if {@code key} is not in the map at all.
*/
boolean replace(K key, long expectedOldValue, long newValue) {
if (expectedOldValue == 0L) {
return putIfAbsent(key, newValue) == 0L;
} else {
return map.replace(key, expectedOldValue, newValue);
}
}
}
代码示例来源:origin: apache/hive
private void addMethodTime(Method method, long timeTaken) {
String methodStr = getMethodString(method);
while (true) {
Long curTime = metaCallTimeMap.get(methodStr), newTime = timeTaken;
if (curTime != null && metaCallTimeMap.replace(methodStr, curTime, newTime + curTime)) break;
if (curTime == null && (null == metaCallTimeMap.putIfAbsent(methodStr, newTime))) break;
}
}
代码示例来源:origin: igniterealtime/Openfire
/**
* Resets (reloads) the properties for a specified subdomain.
*
* @param subdomain the subdomain of the service to reload properties for.
*/
public static void refreshProperties(String subdomain) {
propertyMaps.replace(subdomain, new MUCServiceProperties(subdomain));
}
代码示例来源:origin: sohutv/cachecloud
/**
* If {@code key} is not already associated with a value or if {@code key} is associated with
* zero, associate it with {@code newValue}. Returns the previous value associated with
* {@code key}, or zero if there was no mapping for {@code key}.
*/
long putIfAbsent(K key, long newValue) {
for (; ; ) {
AtomicLong atomic = map.get(key);
if (atomic == null) {
atomic = map.putIfAbsent(key, new AtomicLong(newValue));
if (atomic == null) {
return 0L;
}
// atomic is now non-null; fall through
}
long oldValue = atomic.get();
if (oldValue == 0L) {
// don't compareAndSet a zero
if (map.replace(key, atomic, new AtomicLong(newValue))) {
return 0L;
}
// atomic replaced
continue;
}
return oldValue;
}
}
代码示例来源:origin: wildfly/wildfly
/**
* If {@code (key, expectedOldValue)} is currently in the map, this method replaces {@code
* expectedOldValue} with {@code newValue} and returns true; otherwise, this method returns false.
*
* <p>If {@code expectedOldValue} is zero, this method will succeed if {@code (key, zero)} is
* currently in the map, or if {@code key} is not in the map at all.
*/
boolean replace(K key, long expectedOldValue, long newValue) {
if (expectedOldValue == 0L) {
return putIfAbsent(key, newValue) == 0L;
} else {
return map.replace(key, expectedOldValue, newValue);
}
}
}
代码示例来源:origin: google/j2objc
/**
* If {@code key} is not already associated with a value or if {@code key} is associated with
* zero, associate it with {@code newValue}. Returns the previous value associated with {@code
* key}, or zero if there was no mapping for {@code key}.
*/
long putIfAbsent(K key, long newValue) {
while (true) {
AtomicLong atomic = map.get(key);
if (atomic == null) {
atomic = map.putIfAbsent(key, new AtomicLong(newValue));
if (atomic == null) {
return 0L;
}
// atomic is now non-null; fall through
}
long oldValue = atomic.get();
if (oldValue == 0L) {
// don't compareAndSet a zero
if (map.replace(key, atomic, new AtomicLong(newValue))) {
return 0L;
}
// atomic replaced
continue;
}
return oldValue;
}
}
代码示例来源:origin: h2oai/h2o-2
void stepped(int chunk) {
assert (_trainer != null) == _key.home();
if( _trainer != null )
_trainer._counts.incrementAndGet(chunk);
else {
for( ;; ) {
Integer n = _counters.get(chunk);
if( n == null ) {
if( _counters.putIfAbsent(chunk, 1) == null )
break;
} else {
if( _counters.replace(chunk, n, n + 1) )
break;
}
}
}
}
代码示例来源:origin: igniterealtime/Openfire
@Override
public V replace(K key, V value) {
V priorValue = super.replace(key, value);
if (priorValue != null) {
syncGroups(value, VALUES, ADD);
syncGroups(priorValue, VALUES, REMOVE);
}
return priorValue;
}
代码示例来源:origin: igniterealtime/Openfire
@Override
public boolean replace(K key, V oldValue, V newValue) {
boolean replaced = super.replace(key, oldValue, newValue);
if (replaced) {
syncGroups(oldValue, VALUES, REMOVE);
syncGroups(newValue, VALUES, ADD);
}
return replaced;
}
代码示例来源:origin: apache/geode
protected void setPublicKey(byte[] publickey, InternalDistributedMember mbr) {
try {
memberToPublicKey.put(new InternalDistributedMemberWrapper(mbr), publickey);
peerEncryptors.replace(mbr, new GMSEncryptionCipherPool(this, generateSecret(publickey)));
} catch (Exception e) {
throw new RuntimeException("Unable to create peer encryptor " + mbr, e);
}
}
代码示例来源:origin: jenkinsci/jenkins
if(value==null ? core.putIfAbsent(key,l)!=null : !core.replace(key,value,l)) {
代码示例来源:origin: neo4j/neo4j
@Override
public long release( long id, TransactionHandle transactionHandle )
{
TransactionMarker marker = registry.get( id );
if ( null == marker )
{
throw new IllegalStateException( "Trying to suspend unregistered transaction" );
}
if ( marker.isSuspended() )
{
throw new IllegalStateException( "Trying to suspend transaction that was already suspended" );
}
SuspendedTransaction suspendedTx = new SuspendedTransaction( marker.getActiveTransaction(), transactionHandle );
if ( !registry.replace( id, marker, suspendedTx ) )
{
throw new IllegalStateException( "Trying to suspend transaction that has been concurrently suspended" );
}
return computeNewExpiryTime( suspendedTx.getLastActiveTimestamp() );
}
代码示例来源:origin: neo4j/neo4j
@Override
public TransactionHandle acquire( long id ) throws TransactionLifecycleException
{
TransactionMarker marker = registry.get( id );
if ( null == marker )
{
throw new InvalidTransactionId();
}
SuspendedTransaction transaction = marker.getSuspendedTransaction();
if ( registry.replace( id, marker, marker.getActiveTransaction() ) )
{
return transaction.transactionHandle;
}
else
{
throw new InvalidConcurrentTransactionAccess();
}
}
代码示例来源:origin: neo4j/neo4j
@Override
public TransactionHandle terminate( long id ) throws TransactionLifecycleException
{
TransactionMarker marker = registry.get( id );
if ( null == marker )
{
throw new InvalidTransactionId();
}
TransactionTerminationHandle handle = marker.getActiveTransaction().getTerminationHandle();
handle.terminate();
try
{
SuspendedTransaction transaction = marker.getSuspendedTransaction();
if ( registry.replace( id, marker, marker.getActiveTransaction() ) )
{
return transaction.transactionHandle;
}
}
catch ( InvalidConcurrentTransactionAccess exception )
{
// We could not acquire the transaction. Let the other request clean up.
}
return null;
}
内容来源于网络,如有侵权,请联系作者删除!