Control tracking of non cleaning threads via system property fixes #273 #693
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR is a full refactor of
CleaningThreadLocal
that adds opt-in orphan-tracking, modernises the API, tightens safety contracts and expands the test-suite.New functionality
Global & per-instance orphan-tracking switches
-Ddisable.ctl.orphan.tracking
→ hard-off in prod-ea
) → tracking on by default for debuggingStatic factory helpers
withCloseQuietly(...)
withCleanup(...)
withCleanup(..., Function<T,T> getWrapper)
Lazy, best-effort orphan collection
cleanupNonCleaningThreads()
now delegates to an internaldoCleanup…
helper and returns early when nothing is tracked.Implementation & API refinements
DISABLE_CTL_ORPHAN_TRACKING
constant and richer state fields (trackNonCleaningThreads
, lazily-initialisednonCleaningThreadValues
).Objects.requireNonNull
and annotate parameters/fields with JetBrains@NotNull/@Nullable
.cleanup(T)
is idempotent, swallows/logs user exceptions and is publicly exposed for clarity.toString()
for easier diagnostics.Documentation & metadata
Tests
CleaningThreadLocalOrphanPruningTest
– parameterised test that proves the new tracking flag’s behaviour across 128 orphaned threads.CleaningThreadLocalTest
updated to use the new factory methods and verify thread-safety/cleanup paths.Compatibility notes