Skip to content

Commit 679c0e4

Browse files
committed
Add runtime hints for VirtualThreadSchedulerMXBean
See gh-43594
1 parent 8039030 commit 679c0e4

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/ProcessInfoContributor.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
package org.springframework.boot.actuate.info;
1818

1919
import org.springframework.aot.hint.BindingReflectionHintsRegistrar;
20+
import org.springframework.aot.hint.MemberCategory;
2021
import org.springframework.aot.hint.RuntimeHints;
2122
import org.springframework.aot.hint.RuntimeHintsRegistrar;
2223
import org.springframework.boot.actuate.info.Info.Builder;
@@ -51,6 +52,9 @@ static class ProcessInfoContributorRuntimeHints implements RuntimeHintsRegistrar
5152
@Override
5253
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
5354
this.bindingRegistrar.registerReflectionHints(hints.reflection(), ProcessInfo.class);
55+
hints.reflection()
56+
.registerTypeIfPresent(classLoader, "jdk.management.VirtualThreadSchedulerMXBean",
57+
MemberCategory.INVOKE_PUBLIC_METHODS);
5458
}
5559

5660
}

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/ProcessInfoContributorTests.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,9 +17,12 @@
1717
package org.springframework.boot.actuate.info;
1818

1919
import org.junit.jupiter.api.Test;
20+
import org.junit.jupiter.api.condition.EnabledForJreRange;
21+
import org.junit.jupiter.api.condition.JRE;
2022

2123
import org.springframework.aot.hint.MemberCategory;
2224
import org.springframework.aot.hint.RuntimeHints;
25+
import org.springframework.aot.hint.TypeReference;
2326
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
2427
import org.springframework.boot.actuate.info.ProcessInfoContributor.ProcessInfoContributorRuntimeHints;
2528
import org.springframework.boot.info.ProcessInfo;
@@ -30,6 +33,7 @@
3033
* Tests for {@link ProcessInfoContributor}.
3134
*
3235
* @author Jonatan Ivanov
36+
* @author Moritz Halbritter
3337
*/
3438
class ProcessInfoContributorTests {
3539

@@ -52,4 +56,14 @@ void shouldRegisterHints() {
5256
.accepts(runtimeHints);
5357
}
5458

59+
@Test
60+
@EnabledForJreRange(min = JRE.JAVA_24)
61+
void shouldRegisterRuntimeHintsForVirtualThreadSchedulerMXBean() {
62+
RuntimeHints runtimeHints = new RuntimeHints();
63+
new ProcessInfoContributorRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
64+
assertThat(RuntimeHintsPredicates.reflection()
65+
.onType(TypeReference.of("jdk.management.VirtualThreadSchedulerMXBean"))
66+
.withMemberCategories(MemberCategory.INVOKE_PUBLIC_METHODS)).accepts(runtimeHints);
67+
}
68+
5569
}

0 commit comments

Comments
 (0)