当前位置: 首页>>代码示例>>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;未经允许,请勿转载。