本文整理了Java中java.util.concurrent.atomic.AtomicReference.set()
方法的一些代码示例,展示了AtomicReference.set()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AtomicReference.set()
方法的具体详情如下:
包路径:java.util.concurrent.atomic.AtomicReference
类名称:AtomicReference
方法名:set
[英]Sets to the given value.
[中]设置为给定的值。
代码示例来源:origin: spring-projects/spring-framework
@Override
public Mono<Void> invalidate() {
this.state.set(State.EXPIRED);
getAttributes().clear();
InMemoryWebSessionStore.this.sessions.remove(this.id.get());
return Mono.empty();
}
代码示例来源:origin: stackoverflow.com
AtomicReference<Object> cache = new AtomicReference<Object>();
Object cachedValue = new Object();
cache.set(cachedValue);
//... time passes ...
Object cachedValueToUpdate = cache.get();
//... do some work to transform cachedValueToUpdate into a new version
Object newValue = someFunctionOfOld(cachedValueToUpdate);
boolean success = cache.compareAndSet(cachedValue,cachedValueToUpdate);
代码示例来源:origin: ReactiveX/RxJava
@Override
public void onComplete() {
o.set(-1);
finish.countDown();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void onMonoRejectedDoOnSuccessOrError() {
Mono<String> mp = Mono.error(new Exception("test"));
AtomicReference<Throwable> ref = new AtomicReference<>();
mp.doOnSuccessOrError((s, f) -> ref.set(f))
.subscribe();
assertThat(ref.get()).hasMessage("test");
}
代码示例来源:origin: ReactiveX/RxJava
@Test
@Ignore("Null values not permitted")
public void testSerializeNull() {
final AtomicReference<Subscriber<Integer>> serial = new AtomicReference<Subscriber<Integer>>();
TestSubscriber<Integer> ts = new TestSubscriber<Integer>() {
@Override
public void onNext(Integer t) {
if (t != null && t == 0) {
serial.get().onNext(null);
}
super.onNext(t);
}
};
SerializedSubscriber<Integer> sobs = new SerializedSubscriber<Integer>(ts);
serial.set(sobs);
sobs.onNext(0);
ts.assertValues(0, null);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void test() throws InterruptedException {
Integer actual = (Integer) message.getHeaders().getOrDefault("seq", -1);
if (actual != expected) {
result.set("Expected: " + expected + ", but was: " + actual);
latch.countDown();
return;
result.set(ex.toString());
latch.countDown();
result.set("Done");
latch.countDown();
assertEquals("Done", result.get());
代码示例来源:origin: Graylog2/graylog2-server
@Subscribe
public void lifecycleChanged(Lifecycle lifecycle) {
LOG.debug("Lifecycle is now {}", lifecycle);
// if we switch to RUNNING from STARTING (or unknown) the server is ready to accept connections on inputs.
// we want to postpone opening the inputs earlier, so we don't get swamped with messages before
// we can actually process them.
if (lifecycle == Lifecycle.RUNNING && previousLifecycle.get() == Lifecycle.STARTING || previousLifecycle.get() == Lifecycle.UNINITIALIZED) {
LOG.info("Triggering launching persisted inputs, node transitioned from {} to {}", previousLifecycle.get(), lifecycle);
// Set lifecycle BEFORE counting down the latch to avoid race conditions!
previousLifecycle.set(lifecycle);
startLatch.countDown();
}
// if we failed to start up due to some other service aborting, we need to get over the barrier.
if (lifecycle == Lifecycle.FAILED) {
startLatch.countDown();
}
}
代码示例来源:origin: reactor/reactor-core
@Test
public void onMonoSuccessDoOnSuccessOrError() {
Mono<String> mp = Mono.just("test");
AtomicReference<String> ref = new AtomicReference<>();
mp.doOnSuccessOrError((s, f) -> ref.set(s))
.subscribe();
assertThat(ref.get()).isEqualToIgnoringCase("test");
}
代码示例来源:origin: ReactiveX/RxJava
@Test
@Ignore("Null values not permitted")
public void testSerializeNull() {
final AtomicReference<Observer<Integer>> serial = new AtomicReference<Observer<Integer>>();
TestObserver<Integer> to = new TestObserver<Integer>() {
@Override
public void onNext(Integer t) {
if (t != null && t == 0) {
serial.get().onNext(null);
}
super.onNext(t);
}
};
SerializedObserver<Integer> sobs = new SerializedObserver<Integer>(to);
serial.set(sobs);
sobs.onNext(0);
to.assertValues(0, null);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testExecuteBlockingTTCL() throws Exception {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
assertNotNull(cl);
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<ClassLoader> blockingTCCL = new AtomicReference<>();
vertx.<String>executeBlocking(future -> {
future.complete("whatever");
blockingTCCL.set(Thread.currentThread().getContextClassLoader());
}, ar -> {
assertTrue(ar.succeeded());
assertEquals("whatever", ar.result());
latch.countDown();
});
assertSame(cl, Thread.currentThread().getContextClassLoader());
awaitLatch(latch);
assertSame(cl, blockingTCCL.get());
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public void onError(Throwable e) {
error.set(e);
completed.countDown();
}
代码示例来源:origin: AsyncHttpClient/async-http-client
@Override
public void onTextFrame(String payload, boolean finalFragment, int rsv) {
text.set(text.get() + payload);
textLatch.countDown();
}
代码示例来源:origin: prestodb/presto
@Override
public void lockDownNodes()
{
nodeMap.set(Suppliers.ofInstance(nodeMap.get().get()));
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Get (and initialize, if not initialized yet) the required object
*
* @return lazily initialized object
* @throws ConcurrentException if the initialization of the object causes an
* exception
*/
@Override
public final T get() throws ConcurrentException {
T result;
while ((result = reference.get()) == null) {
if (factory.compareAndSet(null, this)) {
reference.set(initialize());
}
}
return result;
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testFactory() throws Exception {
AtomicReference<Thread> metricsThread = new AtomicReference<>();
AtomicReference<Context> metricsContext = new AtomicReference<>();
VertxMetricsFactory factory = (options) -> {
metricsThread.set(Thread.currentThread());
metricsContext.set(Vertx.currentContext());
return DummyVertxMetrics.INSTANCE;
};
vertx(new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true).setFactory(factory)));
assertSame(Thread.currentThread(), metricsThread.get());
assertNull(metricsContext.get());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void missedSubscriptionNoPrior() {
SubscriptionArbiter sa = new SubscriptionArbiter(true);
sa.getAndIncrement();
BooleanSubscription bs1 = new BooleanSubscription();
sa.missedSubscription.set(bs1);
sa.drainLoop();
assertSame(bs1, sa.actual);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testCallbackInvokedOnFailure() throws Exception {
// will trigger java.net.UnknownHostException
String hostName = "zoom.zoom.zen.tld";
VertxOptions options = new VertxOptions()
.setClusterManager(new FakeClusterManager())
.setClusterHost(hostName);
AtomicReference<AsyncResult<Vertx>> resultRef = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
Vertx.clusteredVertx(options, ar -> {
resultRef.set(ar);
latch.countDown();
});
awaitLatch(latch);
assertFalse(resultRef.get() == null);
assertTrue(resultRef.get().failed());
assertTrue("Was expecting failure to be an instance of UnknownHostException", resultRef.get().cause() instanceof UnknownHostException);
}
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public void onError(Throwable e) {
err.set(e);
cdl.countDown();
}
});
代码示例来源:origin: AsyncHttpClient/async-http-client
@Override
public void onTextFrame(String payload, boolean finalFragment, int rsv) {
text.set(text.get() + payload);
latch.countDown();
}
代码示例来源:origin: spring-projects/spring-framework
@Override
protected void hookOnError(Throwable throwable) {
this.error.set(throwable);
if (this.dataBuffer.get() == null) {
this.sink.error(throwable);
}
}
内容来源于网络,如有侵权,请联系作者删除!