Skip to content

Commit cce008d

Browse files
authored
fix: use core pool size 1 for maintainer (#3314)
The multiplexed session maintainer used a ScheduledExecutorService with a core pool size of zero. This can cause high CPU usage on Java 8 due to https://bugs.openjdk.org/browse/JDK-8129861. Also on higher versions of Java, it is better to use an executor with at least one core thread, instead of letting the executor create a new thread every time a task needs to be executed. Fixes #3313 Fixes https://togithub.com/GoogleCloudPlatform/pgadapter/issues/2249 Fixes https://togithub.com/googleapis/java-spanner-jdbc/issues/1736
1 parent 94caf6d commit cce008d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClient.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,14 @@ public ReadOnlyTransaction readOnlyTransaction(TimestampBound bound) {
390390

391391
/**
392392
* It is enough with one executor to maintain the multiplexed sessions in all the clients, as they
393-
* do not need to be updated often, and the maintenance task is light.
393+
* do not need to be updated often, and the maintenance task is light. The core pool size is set
394+
* to 1 to prevent continuous creating and tearing down threads, and to avoid high CPU usage when
395+
* running on Java 8 due to <a href="https://bugs.openjdk.org/browse/JDK-8129861">
396+
* https://bugs.openjdk.org/browse/JDK-8129861</a>.
394397
*/
395398
private static final ScheduledExecutorService MAINTAINER_SERVICE =
396399
Executors.newScheduledThreadPool(
397-
/* corePoolSize = */ 0,
400+
/* corePoolSize = */ 1,
398401
ThreadFactoryUtil.createVirtualOrPlatformDaemonThreadFactory(
399402
"multiplexed-session-maintainer", /* tryVirtual = */ false));
400403

0 commit comments

Comments
 (0)