Skip to content

Commit

Permalink
[grid] synchronize read from field written by other thread
Browse files Browse the repository at this point in the history
  • Loading branch information
joerg1985 committed Mar 29, 2024
1 parent 3ef121c commit 6cda692
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public HttpResponse addToQueue(SessionRequest request) {
boolean sessionCreated = data.latch.await(requestTimeout.toMillis(), MILLISECONDS);

if (sessionCreated) {
result = data.result;
result = data.getResult();
} else {
result = Either.left(new SessionNotCreatedException("New session request timed out"));
}
Expand Down Expand Up @@ -465,14 +465,18 @@ private class Data {

public final Instant endTime;
private final CountDownLatch latch = new CountDownLatch(1);
public Either<SessionNotCreatedException, CreateSessionResponse> result;
private Either<SessionNotCreatedException, CreateSessionResponse> result;
private boolean complete;

public Data(Instant enqueued) {
this.endTime = enqueued.plus(requestTimeout);
this.result = Either.left(new SessionNotCreatedException("Session not created"));
}

public synchronized Either<SessionNotCreatedException, CreateSessionResponse> getResult() {
return result;
}

public synchronized void setResult(
Either<SessionNotCreatedException, CreateSessionResponse> result) {
if (complete) {
Expand Down

0 comments on commit 6cda692

Please sign in to comment.