Browse Source

Use volatile for subscriber in base publishers

Issue: SPR-16207
pull/1603/head
Rossen Stoyanchev 7 years ago
parent
commit
06b2ab3908
  1. 12
      spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerReadPublisher.java
  2. 2
      spring-web/src/main/java/org/springframework/http/server/reactive/WriteResultPublisher.java

12
spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerReadPublisher.java

@ -52,17 +52,17 @@ public abstract class AbstractListenerReadPublisher<T> implements Publisher<T> {
private volatile long demand; private volatile long demand;
private volatile boolean completionBeforeDemand;
@Nullable
private volatile Throwable errorBeforeDemand;
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
private static final AtomicLongFieldUpdater<AbstractListenerReadPublisher> DEMAND_FIELD_UPDATER = private static final AtomicLongFieldUpdater<AbstractListenerReadPublisher> DEMAND_FIELD_UPDATER =
AtomicLongFieldUpdater.newUpdater(AbstractListenerReadPublisher.class, "demand"); AtomicLongFieldUpdater.newUpdater(AbstractListenerReadPublisher.class, "demand");
@Nullable @Nullable
private Subscriber<? super T> subscriber; private volatile Subscriber<? super T> subscriber;
private volatile boolean completionBeforeDemand;
@Nullable
private volatile Throwable errorBeforeDemand;
// Publisher implementation... // Publisher implementation...

2
spring-web/src/main/java/org/springframework/http/server/reactive/WriteResultPublisher.java

@ -43,7 +43,7 @@ class WriteResultPublisher implements Publisher<Void> {
private final AtomicReference<State> state = new AtomicReference<>(State.UNSUBSCRIBED); private final AtomicReference<State> state = new AtomicReference<>(State.UNSUBSCRIBED);
@Nullable @Nullable
private Subscriber<? super Void> subscriber; private volatile Subscriber<? super Void> subscriber;
private volatile boolean completedBeforeSubscribed; private volatile boolean completedBeforeSubscribed;

Loading…
Cancel
Save