本文整理汇总了Java中java.util.concurrent.atomic.AtomicBoolean类的典型用法代码示例。如果您正苦于以下问题:Java AtomicBoolean类的具体用法?Java AtomicBoolean怎么用?Java AtomicBoolean使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AtomicBoolean类属于java.util.concurrent.atomic包,在下文中一共展示了AtomicBoolean类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testParkAfterUnpark
import java.util.concurrent.atomic.AtomicBoolean; //导入依赖的package包/类
public void testParkAfterUnpark(final ParkMethod parkMethod) {
final CountDownLatch pleaseUnpark = new CountDownLatch(1);
final AtomicBoolean pleasePark = new AtomicBoolean(false);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() {
pleaseUnpark.countDown();
while (!pleasePark.get())
Thread.yield();
parkMethod.park();
}});
await(pleaseUnpark);
LockSupport.unpark(t);
pleasePark.set(true);
awaitTermination(t);
}
示例2: launch
import java.util.concurrent.atomic.AtomicBoolean; //导入依赖的package包/类
private static Process launch(String address, String class_name) throws Exception {
String[] args = VMConnection.insertDebuggeeVMOptions(new String[] {
"-agentlib:jdwp=transport=dt_socket" +
",server=y" + ",suspend=y" + ",address=" + address,
class_name
});
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args);
final AtomicBoolean success = new AtomicBoolean();
Process p = ProcessTools.startProcess(
class_name,
pb,
(line) -> {
// The first thing that will get read is
// Listening for transport dt_socket at address: xxxxx
// which shows the debuggee is ready to accept connections.
success.set(line.contains("Listening for transport dt_socket at address:"));
return true;
},
Integer.MAX_VALUE,
TimeUnit.MILLISECONDS
);
return success.get() ? p : null;
}
示例3: SimplePolicy
import java.util.concurrent.atomic.AtomicBoolean; //导入依赖的package包/类
public SimplePolicy(TestCase test, AtomicBoolean allowAll) {
this.allowAll = allowAll;
permissions = new Permissions();
permissions.add(new LoggingPermission("control", null)); // needed by new FileHandler()
permissions.add(new FilePermission("<<ALL FILES>>", "read")); // needed by new FileHandler()
permissions.add(new FilePermission(logFile, "write,delete")); // needed by new FileHandler()
permissions.add(new FilePermission(logFile+".lck", "write,delete")); // needed by FileHandler.close()
permissions.add(new FilePermission(logFile+".1", "write,delete")); // needed by new FileHandler()
permissions.add(new FilePermission(logFile+".1.lck", "write,delete")); // needed by FileHandler.close()
permissions.add(new FilePermission(tmpLogFile, "write,delete")); // needed by new FileHandler()
permissions.add(new FilePermission(tmpLogFile+".lck", "write,delete")); // needed by FileHandler.close()
permissions.add(new FilePermission(tmpLogFile+".1", "write,delete")); // needed by new FileHandler()
permissions.add(new FilePermission(tmpLogFile+".1.lck", "write,delete")); // needed by FileHandler.close()
permissions.add(new FilePermission(userDir, "write")); // needed by new FileHandler()
permissions.add(new FilePermission(tmpDir, "write")); // needed by new FileHandler()
permissions.add(new PropertyPermission("user.dir", "read"));
permissions.add(new PropertyPermission("java.io.tmpdir", "read"));
allPermissions = new Permissions();
allPermissions.add(new java.security.AllPermission());
}
示例4: getClickAction
import java.util.concurrent.atomic.AtomicBoolean; //导入依赖的package包/类
@Override
public void getClickAction(final Stage stage, final TabFactory tabFactory) {
List<Tab> tabs = FXCollections.observableArrayList(tabFactory.getTabPane().getTabs());
Collections.reverse(tabs);
AtomicBoolean close = new AtomicBoolean(true);
tabs.forEach(t -> {
if(close.get()){
EditorTab eTab = ((EditorTab) t);
if(!eTab.getEditorPane().exit()){
close.set(false);
return;
}else{
logger.debug("Closing tab {}", eTab.getEditorPane().getFile().getPath());
tabFactory.getTabPane().getTabs().remove(eTab);
}
}
});
if(close.get())
stage.close();
}
示例5: PartitionedRegionRebalanceOp
import java.util.concurrent.atomic.AtomicBoolean; //导入依赖的package包/类
/**
* Create a rebalance operation for a single region.
*
* @param region the region to rebalance
* @param simulate true to only simulate rebalancing, without actually doing anything
* @param replaceOfflineData true to replace offline copies of buckets with new live copies of
* buckets
* @param isRebalance true if this op is a full rebalance instead of a more limited redundancy
* recovery
* @param cancelled the AtomicBoolean reference used for cancellation; if any code sets the AB
* value to true then the rebalance will be cancelled
* @param stats the ResourceManagerStats to use for rebalancing stats
*/
public PartitionedRegionRebalanceOp(PartitionedRegion region, boolean simulate,
RebalanceDirector director, boolean replaceOfflineData, boolean isRebalance,
AtomicBoolean cancelled, ResourceManagerStats stats) {
PartitionedRegion leader = ColocationHelper.getLeaderRegion(region);
Assert.assertTrue(leader != null);
// set the region we are rebalancing to be leader of the colocation group.
this.leaderRegion = leader;
this.targetRegion = region;
this.simulate = simulate;
this.director = director;
this.cancelled = cancelled;
this.replaceOfflineData = replaceOfflineData;
this.isRebalance = isRebalance;
this.stats = simulate ? null : stats;
}
示例6: registerSchemaChangedCallback_beginTransaction
import java.util.concurrent.atomic.AtomicBoolean; //导入依赖的package包/类
@Test
public void registerSchemaChangedCallback_beginTransaction() {
final AtomicBoolean listenerCalled = new AtomicBoolean(false);
assertFalse(sharedRealm.hasTable("NewTable"));
sharedRealm.registerSchemaChangedCallback(new OsSharedRealm.SchemaChangedCallback() {
@Override
public void onSchemaChanged() {
assertTrue(sharedRealm.hasTable("NewTable"));
listenerCalled.set(true);
}
});
changeSchemaByAnotherRealm();
sharedRealm.beginTransaction();
assertTrue(listenerCalled.get());
}
示例7: actionPerformed
import java.util.concurrent.atomic.AtomicBoolean; //导入依赖的package包/类
public void actionPerformed(ActionEvent evt, final JTextComponent target) {
final JavaSource js = JavaSource.forDocument(target.getDocument());
if (js == null) {
StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(GoToSupport.class, "WARN_CannotGoToGeneric",1));
return;
}
final int caretPos = target.getCaretPosition();
final AtomicBoolean cancel = new AtomicBoolean();
ProgressUtils.runOffEventDispatchThread(new Runnable() {
@Override
public void run() {
goToImpl(target, js, caretPos, cancel);
}
}, NbBundle.getMessage(JavaKit.class, "goto-super-implementation"), cancel, false);
}
示例8: prepareOffsetCommitResponse
import java.util.concurrent.atomic.AtomicBoolean; //导入依赖的package包/类
private AtomicBoolean prepareOffsetCommitResponse(MockClient client, Node coordinator, final Map<TopicPartition, Long> partitionOffsets) {
final AtomicBoolean commitReceived = new AtomicBoolean(true);
Map<TopicPartition, Errors> response = new HashMap<>();
for (TopicPartition partition : partitionOffsets.keySet())
response.put(partition, Errors.NONE);
client.prepareResponseFrom(new MockClient.RequestMatcher() {
@Override
public boolean matches(AbstractRequest body) {
OffsetCommitRequest commitRequest = (OffsetCommitRequest) body;
for (Map.Entry<TopicPartition, Long> partitionOffset : partitionOffsets.entrySet()) {
OffsetCommitRequest.PartitionData partitionData = commitRequest.offsetData().get(partitionOffset.getKey());
// verify that the expected offset has been committed
if (partitionData.offset != partitionOffset.getValue()) {
commitReceived.set(false);
return false;
}
}
return true;
}
}, offsetCommitResponse(response), coordinator);
return commitReceived;
}
示例9: showCustomizer
import java.util.concurrent.atomic.AtomicBoolean; //导入依赖的package包/类
@Messages({
"PROGRESS_loading_data=Loading project information",
"# {0} - project display name", "LBL_CustomizerTitle=Project Properties - {0}"
})
public void showCustomizer(String preselectedCategory, final String preselectedSubCategory) {
if (dialog != null) {
dialog.setVisible(true);
} else {
final String category = (preselectedCategory != null) ? preselectedCategory : lastSelectedCategory;
final AtomicReference<Lookup> context = new AtomicReference<Lookup>();
ProgressUtils.runOffEventDispatchThread(new Runnable() {
@Override public void run() {
context.set(new ProxyLookup(prepareData(), Lookups.fixed(new SubCategoryProvider(category, preselectedSubCategory))));
}
}, PROGRESS_loading_data(), /* currently unused */new AtomicBoolean(), false);
if (context.get() == null) { // canceled
return;
}
OptionListener listener = new OptionListener();
dialog = ProjectCustomizer.createCustomizerDialog(layerPath, context.get(), category, listener, null);
dialog.addWindowListener(listener);
dialog.setTitle(LBL_CustomizerTitle(ProjectUtils.getInformation(getProject()).getDisplayName()));
dialog.setVisible(true);
}
}
示例10: SelectionTask
import java.util.concurrent.atomic.AtomicBoolean; //导入依赖的package包/类
SelectionTask(Selector selector) {
renewQueue = new ArrayDeque<FDTSelectionKey>();
newQueue = new ArrayDeque<FDTSelectionKey>();
hasToRun = new AtomicBoolean(false);
if (selector == null) {
throw new NullPointerException("Selector cannot be null in SelectionTask constructor");
}
if (!selector.isOpen()) {
throw new IllegalArgumentException("Selector is not open in SelectionTask constructor");
}
this.selector = selector;
hasToRun.set(true);
}
示例11: testCompareLocalOnlyDirectory
import java.util.concurrent.atomic.AtomicBoolean; //导入依赖的package包/类
@Test
public void testCompareLocalOnlyDirectory() throws Exception {
final AtomicBoolean found = new AtomicBoolean();
final Find find = new Find() {
@Override
public boolean find(final Path file) throws BackgroundException {
found.set(true);
return false;
}
@Override
public Find withCache(Cache<Path> cache) {
return this;
}
};
ComparisonServiceFilter s = new ComparisonServiceFilter(new NullSession(new Host(new TestProtocol())) {
}, TimeZone.getDefault(), new DisabledProgressListener()).withFinder(find);
assertEquals(Comparison.local, s.compare(new Path("t", EnumSet.of(Path.Type.directory)), new NullLocal("t") {
@Override
public boolean exists() {
return true;
}
}));
assertTrue(found.get());
}
示例12: waitIfPaused
import java.util.concurrent.atomic.AtomicBoolean; //导入依赖的package包/类
private boolean waitIfPaused() {
AtomicBoolean pause = this.engine.getPause();
if (pause.get()) {
synchronized (this.engine.getPauseLock()) {
if (pause.get()) {
L.d(LOG_WAITING_FOR_RESUME, this.memoryCacheKey);
try {
this.engine.getPauseLock().wait();
L.d(LOG_RESUME_AFTER_PAUSE, this.memoryCacheKey);
} catch (InterruptedException e) {
L.e(LOG_TASK_INTERRUPTED, this.memoryCacheKey);
return true;
}
}
}
}
return isTaskNotActual();
}
示例13: searchOnSuccess
import java.util.concurrent.atomic.AtomicBoolean; //导入依赖的package包/类
@Test
public void searchOnSuccess() {
String location = "San Francisco, CA";
Channel channel = WeatherResponseFactory.createChannel();
when(weatherRepository.getForecast(location)).thenReturn(Single.just(channel));
final AtomicBoolean completableSubscribed = new AtomicBoolean(false);
Completable saveCompletable = Completable.complete().doOnSubscribe(new Consumer<Disposable>() {
@Override
public void accept(Disposable disposable) throws Exception {
completableSubscribed.set(true);
}
});
when(lastForecastStore.save(channel)).thenReturn(saveCompletable);
presenter.search(location);
verify(view).showLoading(false);
checkChannelSet(channel);
assertThat(completableSubscribed.get(), is(true));
assertThat(presenter.getAttributionUrl(), is(channel.getLink()));
}
示例14: testPessimisticProvidePostResolveSuccess
import java.util.concurrent.atomic.AtomicBoolean; //导入依赖的package包/类
/**
* Test the completion and callback invocation of {@link RedFutureHub}
* pessimistic union of provided futures that later were successfully resolved
*/
@Test
public void testPessimisticProvidePostResolveSuccess() throws Throwable {
AtomicBoolean reachedSuccessBlock = new AtomicBoolean(false);
AtomicBoolean reachedFailureBlock = new AtomicBoolean(false);
AtomicBoolean reachedFinallyBlock = new AtomicBoolean(false);
RedFutureHub hub = RedFuture.hub();
OpenRedFuture future1 = hub.provideFuture();
OpenRedFuture future2 = hub.provideFuture();
OpenRedFutureOf<Object> futureOf = hub.provideFutureOf();
RedFuture union = hub.unitePessimistically();
union.addSuccessCallback(() -> reachedSuccessBlock.set(true));
union.addFailureCallback(throwable -> reachedFailureBlock.set(true));
union.addFinallyCallback(() -> reachedFinallyBlock.set(true));
Assert.assertFalse(reachedFinallyBlock.get());
Assert.assertFalse(reachedSuccessBlock.get());
Assert.assertFalse(reachedFailureBlock.get());
future1.resolve();
future2.resolve();
futureOf.resolve(new Object());
Assert.assertTrue(reachedFinallyBlock.get());
Assert.assertTrue(reachedSuccessBlock.get());
Assert.assertFalse(reachedFailureBlock.get());
}
示例15: putIfAbsent
import java.util.concurrent.atomic.AtomicBoolean; //导入依赖的package包/类
/**
* If {@code key} is not already associated with a value or if {@code key} is associated with
* zero, associate it with {@code newValue}. Returns the previous value associated with
* {@code key}, or zero if there was no mapping for {@code key}.
*/
long putIfAbsent(K key, long newValue) {
AtomicBoolean noValue = new AtomicBoolean(false);
Long result =
map.compute(
key,
(k, oldValue) -> {
if (oldValue == null || oldValue == 0) {
noValue.set(true);
return newValue;
} else {
return oldValue;
}
});
return noValue.get() ? 0L : result.longValue();
}