本文整理汇总了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);
}
示例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();
}
示例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();
}
示例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())));
}
};
}
示例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();
}
}
}