Skip to content

Commit

Permalink
Spanner: closed watch-dog daemon threads spawned by Spanner client (#…
Browse files Browse the repository at this point in the history
…4263)

* Fixed Issue - shutting-down WatchDog daemon threads spawned by Spanner client

* Fixed Issue - shutdown watchDog daemon threads spawned by Spanner client

* Minor code formatting

* Fixed Kokoro code format issue
  • Loading branch information
javabrown authored and sduskis committed Dec 31, 2018
1 parent 36fbd97 commit e9ea3d9
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import javax.annotation.Nullable;
import org.threeten.bp.Duration;

Expand Down Expand Up @@ -139,6 +140,8 @@ public class GapicSpannerRpc implements SpannerRpc {
private final Duration checkInterval =
systemProperty(PROPERTY_PERIOD_SECONDS, DEFAULT_PERIOD_SECONDS);

private final ScheduledExecutorService spannerWatchdog;

public static GapicSpannerRpc create(SpannerOptions options) {
return new GapicSpannerRpc(options);
}
Expand Down Expand Up @@ -191,14 +194,15 @@ public GapicSpannerRpc(SpannerOptions options) {
CredentialsProvider credentialsProvider =
GrpcTransportOptions.setUpCredentialsProvider(options);

spannerWatchdog =
Executors.newSingleThreadScheduledExecutor(
new ThreadFactoryBuilder()
.setDaemon(true)
.setNameFormat("Cloud-Spanner-WatchdogProvider-%d")
.build());
WatchdogProvider watchdogProvider =
InstantiatingWatchdogProvider.create()
.withExecutor(
Executors.newSingleThreadScheduledExecutor(
new ThreadFactoryBuilder()
.setDaemon(true)
.setNameFormat("Cloud-Spanner-WatchdogProvider-%d")
.build()))
.withExecutor(spannerWatchdog)
.withCheckInterval(checkInterval)
.withClock(NanoClock.getDefaultClock());

Expand Down Expand Up @@ -572,6 +576,7 @@ public void shutdown() {
this.spannerStub.close();
this.instanceAdminStub.close();
this.databaseAdminStub.close();
this.spannerWatchdog.shutdown();
}

/**
Expand Down

0 comments on commit e9ea3d9

Please sign in to comment.