diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AsyncResultSetImpl.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AsyncResultSetImpl.java index 22e57d1400..d980c90f78 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AsyncResultSetImpl.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AsyncResultSetImpl.java @@ -498,10 +498,12 @@ public ApiFuture setCallback(Executor exec, ReadyCallback cb) { } private void initiateProduceRows() { - if (this.state == State.STREAMING_INITIALIZED) { - this.state = State.RUNNING; + synchronized (monitor) { + if (this.state == State.STREAMING_INITIALIZED) { + this.state = State.RUNNING; + } + produceRowsInitiated = true; } - produceRowsInitiated = true; this.service.execute(new ProduceRowsRunnable()); }