[英]What is the Java equivalent for C# `Interlocked.Exchange(Object, Object) : Object`?
What is the Java equivalent for C# Interlocked.Exchange(Object, Object) : Object
? 什么是C#
Interlocked.Exchange(Object, Object) : Object
的Java等价物Interlocked.Exchange(Object, Object) : Object
? Is there a way in Java to perform the following actions in a single atomic step without lock : 1) store locally the reference of a variable 2) set another reference to the same variable? Java中是否有一种方法可以在没有锁定的单个原子步骤中执行以下操作:1)在本地存储变量的引用2)设置对同一变量的另一个引用?
There's no operation to do this for an arbitrary variable, as far as I'm aware... but this is what the AtomicReference
type is for: 对于任意变量,没有任何操作可以做到这一点,据我所知......但这是
AtomicReference
类型的用途:
private AtomicReference<String> stringReference;
...
String oldValue = stringReference.getAndSet(newValue);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.