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