本文整理了Java中java.util.concurrent.atomic.AtomicReference.getAndSet()
方法的一些代码示例,展示了AtomicReference.getAndSet()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AtomicReference.getAndSet()
方法的具体详情如下:
包路径:java.util.concurrent.atomic.AtomicReference
类名称:AtomicReference
方法名:getAndSet
[英]Atomically sets to the given value and returns the old value.
[中]原子设置为给定值并返回旧值。
代码示例来源:origin: ReactiveX/RxJava
public static <T> Throwable terminate(AtomicReference<Throwable> field) {
Throwable current = field.get();
if (current != TERMINATED) {
current = field.getAndSet(TERMINATED);
}
return current;
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public void shutdown() {
ScheduledExecutorService current = executor.get();
if (current != SHUTDOWN) {
current = executor.getAndSet(SHUTDOWN);
if (current != SHUTDOWN) {
current.shutdownNow();
}
}
}
代码示例来源:origin: redisson/redisson
public static <T> Throwable terminate(AtomicReference<Throwable> field) {
Throwable current = field.get();
if (current != TERMINATED) {
current = field.getAndSet(TERMINATED);
}
return current;
}
代码示例来源:origin: ReactiveX/RxJava
/**
* Atomically disposes the Disposable in the field if not already disposed.
* @param field the target field
* @return true if the current thread managed to dispose the Disposable
*/
public static boolean dispose(AtomicReference<Disposable> field) {
Disposable current = field.get();
Disposable d = DISPOSED;
if (current != d) {
current = field.getAndSet(d);
if (current != d) {
if (current != null) {
current.dispose();
}
return true;
}
}
return false;
}
代码示例来源:origin: apache/incubator-shardingsphere
/**
* Change connection status to running if necessary.
*/
void setRunningStatusIfNecessary() {
if (ConnectionStatus.TRANSACTION != status.get()) {
status.getAndSet(ConnectionStatus.RUNNING);
}
}
代码示例来源:origin: apache/incubator-shardingsphere
/**
* Change connection status to running if necessary.
*/
void setRunningStatusIfNecessary() {
if (ConnectionStatus.TRANSACTION != status.get()) {
status.getAndSet(ConnectionStatus.RUNNING);
}
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public void dispose() {
if (subscribers.get() != TERMINATED) {
@SuppressWarnings("unchecked")
InnerSubscriber[] ps = subscribers.getAndSet(TERMINATED);
if (ps != TERMINATED) {
current.compareAndSet(PublishSubscriber.this, null);
SubscriptionHelper.cancel(upstream);
}
}
}
代码示例来源:origin: ReactiveX/RxJava
@SuppressWarnings("unchecked")
@Override
public void onComplete() {
if (subscribers.get() == TERMINATED) {
return;
}
for (PublishSubscription<T> s : subscribers.getAndSet(TERMINATED)) {
s.onComplete();
}
}
代码示例来源:origin: ReactiveX/RxJava
@SuppressWarnings("unchecked")
BehaviorSubscription<T>[] terminate(Object terminalValue) {
BehaviorSubscription<T>[] a = subscribers.get();
if (a != TERMINATED) {
a = subscribers.getAndSet(TERMINATED);
if (a != TERMINATED) {
// either this or atomics with lots of allocation
setCurrent(terminalValue);
}
}
return a;
}
代码示例来源:origin: ReactiveX/RxJava
@SuppressWarnings("unchecked")
@Override
public void onComplete() {
if (subscribers.get() == TERMINATED) {
return;
}
for (PublishDisposable<T> pd : subscribers.getAndSet(TERMINATED)) {
pd.onComplete();
}
}
代码示例来源:origin: ReactiveX/RxJava
@SuppressWarnings("unchecked")
void disposeInner() {
SwitchMapInnerSubscriber<T, R> a = active.get();
if (a != CANCELLED) {
a = active.getAndSet((SwitchMapInnerSubscriber<T, R>)CANCELLED);
if (a != CANCELLED && a != null) {
a.cancel();
}
}
}
代码示例来源:origin: ReactiveX/RxJava
@SuppressWarnings("unchecked")
void disposeInner() {
SwitchMapInnerObserver<T, R> a = active.get();
if (a != CANCELLED) {
a = active.getAndSet((SwitchMapInnerObserver<T, R>)CANCELLED);
if (a != CANCELLED && a != null) {
a.cancel();
}
}
}
代码示例来源:origin: redisson/redisson
@Override
public void shutdown() {
ScheduledExecutorService current = executor.get();
if (current != SHUTDOWN) {
current = executor.getAndSet(SHUTDOWN);
if (current != SHUTDOWN) {
current.shutdownNow();
}
}
}
代码示例来源:origin: ReactiveX/RxJava
boolean disposeAll() {
upstream.dispose();
InnerObserver<?, ?>[] a = observers.get();
if (a != CANCELLED) {
a = observers.getAndSet(CANCELLED);
if (a != CANCELLED) {
for (InnerObserver<?, ?> inner : a) {
inner.dispose();
}
return true;
}
}
return false;
}
}
代码示例来源:origin: ReactiveX/RxJava
/**
* Atomically swaps in the common cancelled subscription instance
* and cancels the previous subscription if any.
* @param field the target field to dispose the contents of
* @return true if the swap from the non-cancelled instance to the
* common cancelled instance happened in the caller's thread (allows
* further one-time actions).
*/
public static boolean cancel(AtomicReference<Subscription> field) {
Subscription current = field.get();
if (current != CANCELLED) {
current = field.getAndSet(CANCELLED);
if (current != CANCELLED) {
if (current != null) {
current.cancel();
}
return true;
}
}
return false;
}
代码示例来源:origin: redisson/redisson
@Override
public void dispose() {
if (subscribers.get() != TERMINATED) {
@SuppressWarnings("unchecked")
InnerSubscriber[] ps = subscribers.getAndSet(TERMINATED);
if (ps != TERMINATED) {
current.compareAndSet(PublishSubscriber.this, null);
SubscriptionHelper.cancel(s);
}
}
}
代码示例来源:origin: redisson/redisson
@SuppressWarnings("unchecked")
@Override
public void onComplete() {
if (subscribers.get() == TERMINATED) {
return;
}
for (PublishDisposable<T> s : subscribers.getAndSet(TERMINATED)) {
s.onComplete();
}
}
代码示例来源:origin: redisson/redisson
@SuppressWarnings("unchecked")
BehaviorSubscription<T>[] terminate(Object terminalValue) {
BehaviorSubscription<T>[] a = subscribers.get();
if (a != TERMINATED) {
a = subscribers.getAndSet(TERMINATED);
if (a != TERMINATED) {
// either this or atomics with lots of allocation
setCurrent(terminalValue);
}
}
return a;
}
代码示例来源:origin: redisson/redisson
@SuppressWarnings("unchecked")
@Override
public void onComplete() {
if (subscribers.get() == TERMINATED) {
return;
}
for (PublishSubscription<T> s : subscribers.getAndSet(TERMINATED)) {
s.onComplete();
}
}
代码示例来源:origin: redisson/redisson
@SuppressWarnings("unchecked")
void disposeInner() {
SwitchMapInnerSubscriber<T, R> a = active.get();
if (a != CANCELLED) {
a = active.getAndSet((SwitchMapInnerSubscriber<T, R>)CANCELLED);
if (a != CANCELLED && a != null) {
a.cancel();
}
}
}
内容来源于网络,如有侵权,请联系作者删除!