Skip to content

[Fix-18222][JdbcRegistry] Reuse a singleton scheduler executor in JdbcRegistryThreadFactory#18223

Merged
ruanwenjun merged 2 commits into
apache:devfrom
ruanwenjun:fix-18222-jdbc-registry-scheduler-singleton
May 10, 2026
Merged

[Fix-18222][JdbcRegistry] Reuse a singleton scheduler executor in JdbcRegistryThreadFactory#18223
ruanwenjun merged 2 commits into
apache:devfrom
ruanwenjun:fix-18222-jdbc-registry-scheduler-singleton

Conversation

@ruanwenjun
Copy link
Copy Markdown
Member

Was this PR generated or assisted by AI?

YES, ops 4.7

Purpose of the pull request

close #18222

Brief change log

Verify this pull request

This pull request is code cleanup without any test coverage.

(or)

This pull request is already covered by existing tests, such as (please describe tests).

(or)

This change added tests and can be verified as follows:

(or)

Pull Request Notice

Pull Request Notice

If your pull request contains incompatible change, you should also add it to docs/docs/en/guide/upgrade/incompatible.md

@ruanwenjun ruanwenjun requested a review from Gallardot as a code owner May 7, 2026 15:01
@SbloodyS SbloodyS added this to the 3.4.2 milestone May 8, 2026
@SbloodyS SbloodyS added the bug Something isn't working label May 8, 2026
SbloodyS
SbloodyS previously approved these changes May 8, 2026
Copy link
Copy Markdown
Member

@SbloodyS SbloodyS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ruanwenjun ruanwenjun force-pushed the fix-18222-jdbc-registry-scheduler-singleton branch from 2413c5c to 7cf643f Compare May 9, 2026 07:36
@ruanwenjun ruanwenjun added priority:low improvement make more easy to user or prompt friendly and removed bug Something isn't working labels May 9, 2026
@ruanwenjun ruanwenjun force-pushed the fix-18222-jdbc-registry-scheduler-singleton branch from 8d5fb82 to 5da87f9 Compare May 9, 2026 14:54
@ruanwenjun ruanwenjun requested a review from SbloodyS May 10, 2026 00:21
@ruanwenjun ruanwenjun force-pushed the fix-18222-jdbc-registry-scheduler-singleton branch 3 times, most recently from beb7f64 to 735ea25 Compare May 10, 2026 05:31
@ruanwenjun ruanwenjun force-pushed the fix-18222-jdbc-registry-scheduler-singleton branch from db50685 to 70cc7ec Compare May 10, 2026 11:00
…cRegistryThreadFactory

JdbcRegistryThreadFactory#getDefaultSchedulerThreadExecutor returned a
freshly created ScheduledExecutorService on every call, so the four
scheduleWithFixedDelay sites in JdbcRegistryServer#start and
JdbcRegistryDataManager#start each ran on their own pool, while the
shutdown/shutdownNow calls in JdbcRegistry#close and
JdbcRegistryServer#close closed yet another empty pool instead of the
running ones. Daemon threads kept this from leaking on JVM exit, but the
logic was inconsistent and the process held 4x the configured scheduled
threads.

Cache the executor as a lazy singleton (double-checked locking with
volatile) so all callers share one pool and the close calls land on the
actually-running pool.
…er instance

The JdbcRegistryThreadFactory class held a JVM-global singleton
scheduled executor. Multiple JdbcRegistryServer instances (tests,
embedded StandaloneServer) shared the same pool, blurring lifecycle
ownership and forcing JdbcRegistry#close() to shutdownNow() on a pool
that other instances might still be using.

Move the executor onto JdbcRegistryServer as an instance field, inject
it into JdbcRegistryDataManager via the constructor, and shut it down
in JdbcRegistryServer#close(). The state-guard at the top of the
periodic tasks short-circuits any task that observes STOPPED, so a
graceful shutdown() — combined with daemon threads — is enough to stop
the JVM stalling.

Delete the now-unused JdbcRegistryThreadFactory class and its test;
the test only covered JDK ScheduledExecutorService basics and the
static singleton identity that no longer exists.
@ruanwenjun ruanwenjun force-pushed the fix-18222-jdbc-registry-scheduler-singleton branch from 70cc7ec to 4d7c498 Compare May 10, 2026 11:41
@sonarqubecloud
Copy link
Copy Markdown

@ruanwenjun ruanwenjun merged commit a5cddc8 into apache:dev May 10, 2026
122 of 123 checks passed
@ruanwenjun ruanwenjun deleted the fix-18222-jdbc-registry-scheduler-singleton branch May 10, 2026 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend improvement make more easy to user or prompt friendly priority:low test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Improvement] [JdbcRegistry] ScheduledExecutorThreadFactory creates a new instance on each call, close() does not shut down the running thread pool

2 participants