|
107 | 107 | import java.util.concurrent.ExecutionException; |
108 | 108 | import java.util.concurrent.Executors; |
109 | 109 | import java.util.concurrent.Future; |
| 110 | +import java.util.concurrent.ScheduledExecutorService; |
110 | 111 | import javax.annotation.Nullable; |
111 | 112 | import org.threeten.bp.Duration; |
112 | 113 |
|
@@ -139,6 +140,8 @@ public class GapicSpannerRpc implements SpannerRpc { |
139 | 140 | private final Duration checkInterval = |
140 | 141 | systemProperty(PROPERTY_PERIOD_SECONDS, DEFAULT_PERIOD_SECONDS); |
141 | 142 |
|
| 143 | + private final ScheduledExecutorService spannerWatchdog; |
| 144 | + |
142 | 145 | public static GapicSpannerRpc create(SpannerOptions options) { |
143 | 146 | return new GapicSpannerRpc(options); |
144 | 147 | } |
@@ -191,14 +194,15 @@ public GapicSpannerRpc(SpannerOptions options) { |
191 | 194 | CredentialsProvider credentialsProvider = |
192 | 195 | GrpcTransportOptions.setUpCredentialsProvider(options); |
193 | 196 |
|
| 197 | + spannerWatchdog = |
| 198 | + Executors.newSingleThreadScheduledExecutor( |
| 199 | + new ThreadFactoryBuilder() |
| 200 | + .setDaemon(true) |
| 201 | + .setNameFormat("Cloud-Spanner-WatchdogProvider-%d") |
| 202 | + .build()); |
194 | 203 | WatchdogProvider watchdogProvider = |
195 | 204 | InstantiatingWatchdogProvider.create() |
196 | | - .withExecutor( |
197 | | - Executors.newSingleThreadScheduledExecutor( |
198 | | - new ThreadFactoryBuilder() |
199 | | - .setDaemon(true) |
200 | | - .setNameFormat("Cloud-Spanner-WatchdogProvider-%d") |
201 | | - .build())) |
| 205 | + .withExecutor(spannerWatchdog) |
202 | 206 | .withCheckInterval(checkInterval) |
203 | 207 | .withClock(NanoClock.getDefaultClock()); |
204 | 208 |
|
@@ -572,6 +576,7 @@ public void shutdown() { |
572 | 576 | this.spannerStub.close(); |
573 | 577 | this.instanceAdminStub.close(); |
574 | 578 | this.databaseAdminStub.close(); |
| 579 | + this.spannerWatchdog.shutdown(); |
575 | 580 | } |
576 | 581 |
|
577 | 582 | /** |
|
0 commit comments