Skip to content

Commit

Permalink
fix: use core pool size 1 for maintainer (#3314)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
olavloite authored Aug 30, 2024
1 parent 94caf6d commit cce008d
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,14 @@ public ReadOnlyTransaction readOnlyTransaction(TimestampBound bound) {

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

Expand Down

0 comments on commit cce008d

Please sign in to comment.