Skip to content

Commit e165260

Browse files
authored
Create Virtual Thread worker pool metrics only if needed (#5719)
* Create Virtual Thread worker pool metrics only if needed Follows-up on #5705 Without this change, virtual thread worker pool metrics are registered and published, even when the applications run on JVM without VT support. Signed-off-by: Thomas Segismont <[email protected]> * Fix testVirtualThreadWorkerPoolMetrics Signed-off-by: Thomas Segismont <[email protected]> --------- Signed-off-by: Thomas Segismont <[email protected]>
1 parent c51785c commit e165260

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

vertx-core/src/main/java/io/vertx/core/impl/VertxImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ private static ThreadFactory virtualThreadFactory() {
203203
PoolMetrics internalBlockingPoolMetrics = metrics != null ? metrics.createPoolMetrics("worker", "vert.x-internal-blocking", internalBlockingPoolSize) : null;
204204

205205
ThreadFactory virtualThreadFactory = virtualThreadFactory();
206-
PoolMetrics virtualThreadWorkerPoolMetrics = metrics != null ? metrics.createPoolMetrics("worker", "vert.x-virtual-thread", -1) : null;
206+
PoolMetrics virtualThreadWorkerPoolMetrics = metrics != null && virtualThreadFactory != null ? metrics.createPoolMetrics("worker", "vert.x-virtual-thread", -1) : null;
207207

208208
contextLocals = LocalSeq.get();
209209
contextLocalsList = Collections.unmodifiableList(Arrays.asList(contextLocals));

vertx-core/src/test/java/io/vertx/tests/metrics/MetricsTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,13 @@ public void close() {
12551255
@Test
12561256
public void testVirtualThreadWorkerPoolMetrics() {
12571257
Map<String, FakePoolMetrics> all = FakePoolMetrics.getMetrics();
1258-
assertTrue(all.containsKey("vert.x-virtual-thread"));
1259-
assertNotNull(all.get("vert.x-virtual-thread"));
1258+
VertxInternal vertxInternal = (VertxInternal) vertx;
1259+
if (vertxInternal.isVirtualThreadAvailable()) {
1260+
assertTrue(all.containsKey("vert.x-virtual-thread"));
1261+
assertNotNull(all.get("vert.x-virtual-thread"));
1262+
} else {
1263+
assertFalse(all.containsKey("vert.x-virtual-thread"));
1264+
assertNull(all.get("vert.x-virtual-thread"));
1265+
}
12601266
}
12611267
}

0 commit comments

Comments
 (0)