本文整理汇总了Java中java.util.concurrent.atomic.AtomicReference.getAndSet方法的典型用法代码示例。如果您正苦于以下问题:Java AtomicReference.getAndSet方法的具体用法?Java AtomicReference.getAndSet怎么用?Java AtomicReference.getAndSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.atomic.AtomicReference
的用法示例。
在下文中一共展示了AtomicReference.getAndSet方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createBlockingResultSet
import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
private ResultSet<String> createBlockingResultSet(BlockingQueue<String> queue, Supplier<Boolean> finished) {
AtomicReference<String> ref = new AtomicReference<>();
AtomicInteger sizeref = new AtomicInteger(0);
Iterator<String> blockingIterator = new Iterator<String>() {
@Override
public boolean hasNext() {
if (ref.get() != null) return true;
while (!finished.get()) {
if (ref.get() != null) return true;
try {
ref.set(queue.poll(1000, TimeUnit.MILLISECONDS));
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
return ref.get() != null;
}
@Override
public String next() {
sizeref.incrementAndGet();
return ref.getAndSet(null);
}
};
return createResultSet(blockingIterator);
}
示例2: terminate
import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
public static <T> Throwable terminate(AtomicReference<Throwable> field) {
Throwable current = field.get();
if (current != TERMINATED) {
current = field.getAndSet(TERMINATED);
}
return current;
}
示例3: terminate
import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
public static Throwable terminate(AtomicReference<Throwable> errors) {
Throwable a = (Throwable)errors.getAcquire();
if (a != TERMINATED) {
a = (Throwable)errors.getAndSet(TERMINATED);
}
return a;
}
示例4: cancel
import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
public static boolean cancel(AtomicReference<Flow.Subscription> field) {
Flow.Subscription a = field.getAcquire();
if (a != CANCELLED) {
a = field.getAndSet(CANCELLED);
if (a != CANCELLED) {
if (a != null) {
a.cancel();
}
return true;
}
}
return false;
}