當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。