Skip to content

Commit 14002f6

Browse files
Ensure DataLoaderSubscriber is only called by one thread
Multiple threads may call `onNext` - we thus (lazily) chuck a `synchronized` to ensure correctness at the cost of speed. In future, we should examine how we should manage this concurrency better.
1 parent 0d0b2f8 commit 14002f6

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/main/java/org/dataloader/DataLoaderHelper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,10 @@ public void onSubscribe(Subscription subscription) {
648648
subscription.request(keys.size());
649649
}
650650

651+
// onNext may be called by multiple threads - for the time being, we pass 'synchronized' to guarantee
652+
// correctness (at the cost of speed).
651653
@Override
652-
public void onNext(V value) {
654+
public synchronized void onNext(V value) {
653655
assertState(!onErrorCalled, () -> "onError has already been called; onNext may not be invoked.");
654656
assertState(!onCompleteCalled, () -> "onComplete has already been called; onNext may not be invoked.");
655657

0 commit comments

Comments
 (0)