当前位置: 首页>>代码示例>>Java>>正文


Java AtomicBoolean.getAndSet方法代码示例

本文整理汇总了Java中java.util.concurrent.atomic.AtomicBoolean.getAndSet方法的典型用法代码示例。如果您正苦于以下问题:Java AtomicBoolean.getAndSet方法的具体用法?Java AtomicBoolean.getAndSet怎么用?Java AtomicBoolean.getAndSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.atomic.AtomicBoolean的用法示例。


在下文中一共展示了AtomicBoolean.getAndSet方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testJobManagerAdvancesJobQueueOnceAJobFinishesExecuting

import java.util.concurrent.atomic.AtomicBoolean; //导入方法依赖的package包/类
@Test
public void testJobManagerAdvancesJobQueueOnceAJobFinishesExecuting() throws InterruptedException, ExecutionException, TimeoutException {
    final AtomicBoolean isFirst = new AtomicBoolean(true);
    final SimpleCancelablePromise<JobExecutionResult> firstExcutionPromise = new SimpleCancelablePromise<>();
    final SimpleCancelablePromise<JobExecutionResult> secondExecutionPromise = new SimpleCancelablePromise<>();

    final Supplier<CancelablePromise<JobExecutionResult>> promiseSupplier = () ->
            isFirst.getAndSet(false) ? firstExcutionPromise : secondExecutionPromise;

    final MockJobExecutor mockJobExecutor = MockJobExecutor.thatUses(promiseSupplier);

    final int maxRunningJobs = 1;

    final JobManager jobManager = createManagerWith(mockJobExecutor, maxRunningJobs);

    final CancelablePromise<FinalizedJob> firstJobPromise = jobManager.submit(STANDARD_VALID_REQUEST).getRight();
    final CancelablePromise<FinalizedJob> secondJobPromise = jobManager.submit(STANDARD_VALID_REQUEST).getRight();

    firstExcutionPromise.complete(new JobExecutionResult(FINISHED));
    firstJobPromise.get(1, TimeUnit.SECONDS);

    secondExecutionPromise.complete(new JobExecutionResult(FINISHED));
    secondJobPromise.get(1, TimeUnit.SECONDS);
}
 
开发者ID:adamkewley,项目名称:jobson,代码行数:25,代码来源:JobManagerTest.java

示例2: shouldContinueRunningAfterExceptionInTask

import java.util.concurrent.atomic.AtomicBoolean; //导入方法依赖的package包/类
@Test
public void shouldContinueRunningAfterExceptionInTask(){
    AtomicBoolean firstRun = new AtomicBoolean(true);
    CompletableSubject completedSecondRun = CompletableSubject.create();
    KeyedTaskBuffer<String, Integer> taskBuffer = new KeyedTaskBuffer<>(BUFFER_SIZE_2, MAX_WAIT_MILLIS_100,
            (key, batch) -> {
                if(firstRun.getAndSet(false)){
                    throw new RuntimeException("Test exception");
                }else{
                    completedSecondRun.onComplete();
                }
            });
    taskBuffer.addData(KEY_A, 1);
    taskBuffer.addData(KEY_B, 1);

    //unit test can only finish if this is completed
    completedSecondRun.timeout(1000, TimeUnit.MILLISECONDS).blockingAwait();
}
 
开发者ID:Bandwidth,项目名称:async-sqs,代码行数:19,代码来源:KeyedTaskBufferTest.java

示例3: groupedImports

import java.util.concurrent.atomic.AtomicBoolean; //导入方法依赖的package包/类
public String groupedImports(Collection<Import> allImports) {
  StringBuilder sb = new StringBuilder();
  Map<Integer,ArrayList<Import>> staticImports = groupStatic(allImports);
  Map<Integer,ArrayList<Import>> nonStaticImports = groupNonStatic(allImports);

  Map<Integer,ArrayList<Import>> first = getStaticAfter() ? nonStaticImports : staticImports;
  Map<Integer,ArrayList<Import>> second = getStaticAfter() ? staticImports : nonStaticImports;

  AtomicBoolean firstGroup = new AtomicBoolean(true);
  Consumer<ArrayList<Import>> consumer = grouping -> {
    if (!firstGroup.getAndSet(false)) {
      sb.append("\n");
    }
    grouping.forEach(imp -> sb.append(imp).append("\n"));
  };
  first.values().forEach(consumer);
  if (!getJoinStaticWithNonStatic() && !first.isEmpty() && !second.isEmpty()) {
    sb.append("\n");
  }
  firstGroup.set(true);
  second.values().forEach(consumer);

  // allImports.forEach(x -> System.out.print("-----\n" + x + "\n-----"));
  return sb.toString();
}
 
开发者ID:revelc,项目名称:impsort-maven-plugin,代码行数:26,代码来源:Grouper.java

示例4: writeOnceSoToFailOptimisticConcurrencyCheck

import java.util.concurrent.atomic.AtomicBoolean; //导入方法依赖的package包/类
private IdempotentEventStreamWriter.IsCompatible writeOnceSoToFailOptimisticConcurrencyCheck() {
    AtomicBoolean shouldWrite = new AtomicBoolean(true);
    return (a, b) -> {
        if (shouldWrite.getAndSet(false)) {
            store.write(stream, singletonList(newEvent("type", "data2".getBytes(), "metadata".getBytes())));
        }
    };
}
 
开发者ID:tim-group,项目名称:tg-eventstore,代码行数:9,代码来源:IdempotentEventStreamWriterTest.java

示例5: run

import java.util.concurrent.atomic.AtomicBoolean; //导入方法依赖的package包/类
@Override
public void run(String... args) throws Exception {
  if (!environment.acceptsProfiles("production") && !environment.acceptsProfiles("test")) {
    AtomicBoolean registered = (AtomicBoolean) Restarter.getInstance().getOrAddAttribute("yarnStarted", AtomicBoolean::new);
    boolean alreadyRun = registered.getAndSet(true);
    if (!alreadyRun) {
      startFrontend();
    }
  }
}
 
开发者ID:wlindner,项目名称:ReBoot,代码行数:11,代码来源:YarnRunner.java


注:本文中的java.util.concurrent.atomic.AtomicBoolean.getAndSet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。