You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by "merlimat (via GitHub)" <gi...@apache.org> on 2026/07/10 02:21:26 UTC
[PR] Use ThreadLocalRandom for thread selection in OrderedExecutor [bookkeeper]
merlimat opened a new pull request, #4832:
URL: https://github.com/apache/bookkeeper/pull/4832
### Motivation
`OrderedExecutor.chooseThread()` — the path behind the keyless `submit()`/`execute()` overloads and `chooseThread(null)` — picks a thread using a single shared `java.util.Random` instance. `Random.nextInt()` is a CAS retry loop over one shared `AtomicLong` seed, so when many threads submit keyless tasks to a shared executor they all contend on the same cache line, purely to produce a thread index.
### Changes
Use `ThreadLocalRandom.current().nextInt(...)` for the random routing (no shared state, no CAS contention) and remove the now-unused `rand` field.
Verified with `TestOrderedExecutor` and `TestOrderedExecutorDecorators` (all pass) and module checkstyle.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Use ThreadLocalRandom for thread selection in OrderedExecutor [bookkeeper]
Posted by "merlimat (via GitHub)" <gi...@apache.org>.
merlimat merged PR #4832:
URL: https://github.com/apache/bookkeeper/pull/4832
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org