RFR: CODETOOLS-7902839: JMH: Replace the use of ThreadLocal with explicitly managed thread map

Aleksey Shipilev shade at openjdk.java.net
Tue Mar 9 14:37:28 UTC 2021


SonarCloud instance reports the potential problem in BenchmarkHandler: 'Call "remove()" on "threadData"'

   private final ThreadLocal<ThreadData> threadData;

This actually points to the lifecycle problem with `ThreadLocal`-s in `BenchmarkHandler`. We use it to pass and cache the thread-specific instances and thread parameters with benchmark threads, so that threads can reenter on each iteration and still have the same instances to work on.

Normally, this would be cleaned up when Threads die. They normally do, as default `Executor` shuts down most of the time. But this is not the case for Executors that are not shut down, for example, common pool. In this case, `ThreadLocal`-s would be held until the VM exits.

This should be cleaned up not to use `ThreadLocal`.

-------------

Commit messages:
 - CODETOOLS-7902839: JMH: Replace the use of ThreadLocal with explicitly managed thread map

Changes: https://git.openjdk.java.net/jmh/pull/26/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jmh&pr=26&range=00
  Issue: https://bugs.openjdk.java.net/browse/CODETOOLS-7902839
  Stats: 53 lines in 1 file changed: 26 ins; 14 del; 13 mod
  Patch: https://git.openjdk.java.net/jmh/pull/26.diff
  Fetch: git fetch https://git.openjdk.java.net/jmh pull/26/head:pull/26

PR: https://git.openjdk.java.net/jmh/pull/26


More information about the jmh-dev mailing list