本文整理匯總了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;
}