Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions sdk/src/main/java/io/dapr/client/DaprHttpBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import okhttp3.OkHttpClient;

import java.time.Duration;
import java.util.concurrent.atomic.AtomicReference;

/**
* A builder for the DaprHttp.
Expand All @@ -19,7 +18,7 @@ public class DaprHttpBuilder {
/**
* Singleton OkHttpClient.
*/
private static final AtomicReference<OkHttpClient> OK_HTTP_CLIENT = new AtomicReference<>();
private static volatile OkHttpClient OK_HTTP_CLIENT;

/**
* Static lock object.
Expand All @@ -42,18 +41,17 @@ public DaprHttp build() {
* @return Instance of {@link DaprHttp}
*/
private DaprHttp buildDaprHttp() {
if (OK_HTTP_CLIENT.get() == null) {
if (OK_HTTP_CLIENT == null) {
synchronized (LOCK) {
if (OK_HTTP_CLIENT.get() == null) {
if (OK_HTTP_CLIENT == null) {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
Duration readTimeout = Duration.ofSeconds(Properties.HTTP_CLIENT_READ_TIMEOUT_SECONDS.get());
builder.readTimeout(readTimeout);
OkHttpClient okHttpClient = builder.build();
OK_HTTP_CLIENT.set(okHttpClient);
OK_HTTP_CLIENT = builder.build();
}
}
}

return new DaprHttp(Properties.SIDECAR_IP.get(), Properties.HTTP_PORT.get(), OK_HTTP_CLIENT.get());
return new DaprHttp(Properties.SIDECAR_IP.get(), Properties.HTTP_PORT.get(), OK_HTTP_CLIENT);
}
}