5353import com .google .api .gax .rpc .ServerStream ;
5454import com .google .cloud .Timestamp ;
5555import com .google .cloud .Tuple ;
56- import com .google .cloud .grpc .GrpcTransportOptions ;
57- import com .google .cloud .grpc .GrpcTransportOptions .ExecutorFactory ;
5856import com .google .cloud .spanner .Options .QueryOption ;
5957import com .google .cloud .spanner .Options .ReadOption ;
6058import com .google .cloud .spanner .Options .TransactionOption ;
102100import java .util .concurrent .CountDownLatch ;
103101import java .util .concurrent .ExecutionException ;
104102import java .util .concurrent .Executor ;
103+ import java .util .concurrent .Executors ;
105104import java .util .concurrent .ScheduledExecutorService ;
106105import java .util .concurrent .ScheduledFuture ;
107106import java .util .concurrent .TimeUnit ;
@@ -2263,7 +2262,6 @@ enum Position {
22632262 private final SessionClient sessionClient ;
22642263 private final int numChannels ;
22652264 private final ScheduledExecutorService executor ;
2266- private final ExecutorFactory <ScheduledExecutorService > executorFactory ;
22672265
22682266 final PoolMaintainer poolMaintainer ;
22692267 private final Clock clock ;
@@ -2369,7 +2367,6 @@ static SessionPool createPool(
23692367 return createPool (
23702368 sessionPoolOptions ,
23712369 spannerOptions .getDatabaseRole (),
2372- ((GrpcTransportOptions ) spannerOptions .getTransportOptions ()).getExecutorFactory (),
23732370 sessionClient ,
23742371 poolMaintainerClock == null ? new Clock () : poolMaintainerClock ,
23752372 Position .RANDOM ,
@@ -2384,23 +2381,15 @@ static SessionPool createPool(
23842381
23852382 static SessionPool createPool (
23862383 SessionPoolOptions poolOptions ,
2387- ExecutorFactory <ScheduledExecutorService > executorFactory ,
23882384 SessionClient sessionClient ,
23892385 TraceWrapper tracer ,
23902386 OpenTelemetry openTelemetry ) {
23912387 return createPool (
2392- poolOptions ,
2393- executorFactory ,
2394- sessionClient ,
2395- new Clock (),
2396- Position .RANDOM ,
2397- tracer ,
2398- openTelemetry );
2388+ poolOptions , sessionClient , new Clock (), Position .RANDOM , tracer , openTelemetry );
23992389 }
24002390
24012391 static SessionPool createPool (
24022392 SessionPoolOptions poolOptions ,
2403- ExecutorFactory <ScheduledExecutorService > executorFactory ,
24042393 SessionClient sessionClient ,
24052394 Clock clock ,
24062395 Position initialReleasePosition ,
@@ -2409,7 +2398,6 @@ static SessionPool createPool(
24092398 return createPool (
24102399 poolOptions ,
24112400 null ,
2412- executorFactory ,
24132401 sessionClient ,
24142402 clock ,
24152403 initialReleasePosition ,
@@ -2425,7 +2413,6 @@ static SessionPool createPool(
24252413 static SessionPool createPool (
24262414 SessionPoolOptions poolOptions ,
24272415 String databaseRole ,
2428- ExecutorFactory <ScheduledExecutorService > executorFactory ,
24292416 SessionClient sessionClient ,
24302417 Clock clock ,
24312418 Position initialReleasePosition ,
@@ -2440,8 +2427,6 @@ static SessionPool createPool(
24402427 new SessionPool (
24412428 poolOptions ,
24422429 databaseRole ,
2443- executorFactory ,
2444- executorFactory .get (),
24452430 sessionClient ,
24462431 clock ,
24472432 initialReleasePosition ,
@@ -2459,8 +2444,6 @@ static SessionPool createPool(
24592444 private SessionPool (
24602445 SessionPoolOptions options ,
24612446 String databaseRole ,
2462- ExecutorFactory <ScheduledExecutorService > executorFactory ,
2463- ScheduledExecutorService executor ,
24642447 SessionClient sessionClient ,
24652448 Clock clock ,
24662449 Position initialReleasePosition ,
@@ -2473,8 +2456,11 @@ private SessionPool(
24732456 AtomicLong numMultiplexedSessionsReleased ) {
24742457 this .options = options ;
24752458 this .databaseRole = databaseRole ;
2476- this .executorFactory = executorFactory ;
2477- this .executor = executor ;
2459+ this .executor =
2460+ Executors .newScheduledThreadPool (
2461+ 1 ,
2462+ ThreadFactoryUtil .createVirtualOrPlatformDaemonThreadFactory (
2463+ "session-pool-maintainer" , true ));
24782464 this .sessionClient = sessionClient ;
24792465 this .numChannels = sessionClient .getSpanner ().getOptions ().getNumChannels ();
24802466 this .clock = clock ;
@@ -3064,6 +3050,7 @@ ListenableFuture<Void> closeAsync(ClosedException closedException) {
30643050 pendingClosure += 1 ; // For pool maintenance thread
30653051 poolMaintainer .close ();
30663052 }
3053+ executor .shutdown ();
30673054
30683055 sessions .clear ();
30693056 for (PooledSessionFuture session : checkedOutSessions ) {
@@ -3097,7 +3084,6 @@ ListenableFuture<Void> closeAsync(ClosedException closedException) {
30973084 }
30983085 }
30993086
3100- retFuture .addListener (() -> executorFactory .release (executor ), MoreExecutors .directExecutor ());
31013087 return retFuture ;
31023088 }
31033089
0 commit comments