當前位置: 首頁>>代碼示例>>Java>>正文


Java AtomicReference.getAndSet方法代碼示例

本文整理匯總了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);
}
 
開發者ID:mnemonic-no,項目名稱:common-services,代碼行數:27,代碼來源:ServiceMessageHandlerTest.java

示例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;
}
 
開發者ID:akarnokd,項目名稱:RxJava3-preview,代碼行數:8,代碼來源:ExceptionHelper.java

示例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;
}
 
開發者ID:akarnokd,項目名稱:Reactive4JavaFlow,代碼行數:8,代碼來源:ExceptionHelper.java

示例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;
}
 
開發者ID:akarnokd,項目名稱:Reactive4JavaFlow,代碼行數:14,代碼來源:VarHandleCostPerf.java


注:本文中的java.util.concurrent.atomic.AtomicReference.getAndSet方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。