Skip to content

Commit a625649

Browse files
authored
Document requirements for reflective access in ExecutorServiceMetrics (#6034)
See #6008 (review) Signed-off-by: Johnny Lim <[email protected]>
1 parent e7c337e commit a625649

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

docs/modules/ROOT/pages/reference/jvm.adoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ another. The reported value underestimates the actual total number of steals whe
4545
* `executor.parallelism` (`Gauge`): The targeted parallelism level of this pool.
4646
* `executor.pool.size` (`Gauge`): The current number of threads in the pool.
4747

48+
To use the following `ExecutorService` instances, `--add-opens java.base/java.util.concurrent=ALL-UNNAMED` is required:
49+
50+
* `Executors.newSingleThreadScheduledExecutor()`
51+
* `Executors.newSingleThreadExecutor()`
52+
* `Executors.newThreadPerTaskExecutor()`
53+
* `Executors.newVirtualThreadPerTaskExecutor()`
54+
4855
== Java 21 Metrics
4956

5057
Micrometer provides support for https://openjdk.org/jeps/444[virtual threads] released in Java 21. In order to utilize it, you need to add the `io.micrometer:micrometer-java21` dependency to your classpath to use the binder:

micrometer-core/src/main/java/io/micrometer/core/instrument/binder/jvm/ExecutorServiceMetrics.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@
5050
* {@link ExecutorService}, like {@link TimedExecutorService}. Make sure to pass the
5151
* underlying, unwrapped ExecutorService to this MeterBinder, if it is wrapped in another
5252
* type.
53+
* <p>
54+
* To use the following {@link ExecutorService} instances,
55+
* {@literal --add-opens java.base/java.util.concurrent=ALL-UNNAMED} is required:
56+
* <ul>
57+
* <li>Executors.newSingleThreadScheduledExecutor()</li>
58+
* <li>Executors.newSingleThreadExecutor()</li>
59+
* <li>Executors.newThreadPerTaskExecutor()</li>
60+
* <li>Executors.newVirtualThreadPerTaskExecutor()</li>
61+
* </ul>
5362
*
5463
* @author Jon Schneider
5564
* @author Clint Checketts
@@ -315,14 +324,18 @@ else if (executorService instanceof ForkJoinPool) {
315324
monitor(registry, (ForkJoinPool) executorService);
316325
}
317326
else if (allowIllegalReflectiveAccess) {
327+
// For Executors.newSingleThreadScheduledExecutor()
318328
if (className.equals("java.util.concurrent.Executors$DelegatedScheduledExecutorService")) {
319329
monitor(registry, unwrapThreadPoolExecutor(executorService, executorService.getClass()));
320330
}
331+
// For Executors.newSingleThreadExecutor()
321332
else if (className.equals("java.util.concurrent.Executors$FinalizableDelegatedExecutorService")
322333
|| className.equals("java.util.concurrent.Executors$AutoShutdownDelegatedExecutorService")) {
323334
monitor(registry,
324335
unwrapThreadPoolExecutor(executorService, executorService.getClass().getSuperclass()));
325336
}
337+
// For Executors.newThreadPerTaskExecutor() and
338+
// Executors.newVirtualThreadPerTaskExecutor()
326339
else if (className.equals(CLASS_NAME_THREAD_PER_TASK_EXECUTOR)) {
327340
monitorThreadPerTaskExecutor(registry, executorService);
328341
}

0 commit comments

Comments
 (0)