本文整理汇总了Java中java.util.concurrent.atomic.AtomicReferenceFieldUpdater.getAndSet方法的典型用法代码示例。如果您正苦于以下问题:Java AtomicReferenceFieldUpdater.getAndSet方法的具体用法?Java AtomicReferenceFieldUpdater.getAndSet怎么用?Java AtomicReferenceFieldUpdater.getAndSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.atomic.AtomicReferenceFieldUpdater
的用法示例。
在下文中一共展示了AtomicReferenceFieldUpdater.getAndSet方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dispose
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //导入方法依赖的package包/类
/**
* Atomically dispose the {@link Disposable} in the field if not already disposed.
*
* @param updater the target field updater
* @param holder the target instance holding the field
* @return true if the {@link Disposable} held by the field was properly disposed
*/
static <T> boolean dispose(AtomicReferenceFieldUpdater<T, Disposable> updater, T holder) {
Disposable current = updater.get(holder);
Disposable d = DISPOSED;
if (current != d) {
current = updater.getAndSet(holder, d);
if (current != d) {
if (current != null) {
current.dispose();
}
return true;
}
}
return false;
}
示例2: dispose
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //导入方法依赖的package包/类
/**
* Atomically dispose the {@link Disposable} in the field if not already disposed.
*
* @param updater the target field updater
* @param holder the target instance holding the field
* @return true if the {@link Disposable} held by the field was properly disposed
*/
public static <T> boolean dispose(AtomicReferenceFieldUpdater<T, Disposable> updater, T holder) {
Disposable current = updater.get(holder);
Disposable d = DISPOSED;
if (current != d) {
current = updater.getAndSet(holder, d);
if (current != d) {
if (current != null) {
current.dispose();
}
return true;
}
}
return false;
}
示例3: terminate
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //导入方法依赖的package包/类
/**
* Atomically terminates the subscription if it is not already a
* {@link #cancelledSubscription()}, cancelling the subscription and setting the field
* to the singleton {@link #cancelledSubscription()}.
*
* @param <F> the instance type containing the field
* @param field the field accessor
* @param instance the parent instance
* @return true if terminated, false if the subscription was already terminated
*/
public static <F> boolean terminate(AtomicReferenceFieldUpdater<F, Subscription> field,
F instance) {
Subscription a = field.get(instance);
if (a != CancelledSubscription.INSTANCE) {
a = field.getAndSet(instance, CancelledSubscription.INSTANCE);
if (a != null && a != CancelledSubscription.INSTANCE) {
a.cancel();
return true;
}
}
return false;
}
示例4: terminate
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //导入方法依赖的package包/类
/**
* Atomic utility to safely mark a volatile throwable reference with a terminal
* marker.
*
* @param field the atomic container
* @param instance the reference instance
* @param <T> the instance type
*
* @return the previously masked throwable
*/
@Nullable
public static <T> Throwable terminate(AtomicReferenceFieldUpdater<T, Throwable> field,
T instance) {
Throwable current = field.get(instance);
if (current != TERMINATED) {
current = field.getAndSet(instance, TERMINATED);
}
return current;
}