Skip to content

Commit b0ca0cd

Browse files
committed
wip
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent 1300484 commit b0ca0cd

5 files changed

Lines changed: 19 additions & 9 deletions

File tree

‎docs/content/en/docs/documentation/operations/configuration.md‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ reasonable with platform threads.
4545

4646
Two things to keep in mind:
4747

48-
- Virtual threads require Java 21 or later at runtime. When the flag is set on an older JVM, a
48+
- Virtual threads are officially supported on **Java 25 or later**. They exist from Java 21 on and
49+
the flag does enable them there, but before Java 25 a virtual thread pins its carrier thread
50+
while it is inside a `synchronized` block, which can starve the carrier pool. [JEP
51+
491](https://openjdk.org/jeps/491), delivered in Java 25, removed that pinning, so this is the
52+
baseline the framework supports. On a JVM without virtual threads at all (below Java 21) a
4953
warning is logged and platform threads are used instead, so the same configuration works on any
5054
supported Java version.
5155
- A custom `ExecutorService` provided through `withExecutorService(...)` or
@@ -293,7 +297,7 @@ All operator-level keys are prefixed with `josdk.`.
293297
|---|---|---|
294298
| `josdk.check-crd` | `Boolean` | Validate CRDs against local model on startup |
295299
| `josdk.close-client-on-stop` | `Boolean` | Close the Kubernetes client when the operator stops |
296-
| `josdk.use-virtual-threads` | `Boolean` | Run the framework's concurrent work on virtual threads (requires Java 21+ at runtime) |
300+
| `josdk.use-virtual-threads` | `Boolean` | Run the framework's concurrent work on virtual threads (officially supported on Java 25+ at runtime) |
297301
| `josdk.use-ssa-to-patch-primary-resource` | `Boolean` | Use Server-Side Apply to patch the primary resource |
298302
| `josdk.clone-secondary-resources-when-getting-from-cache` | `Boolean` | Clone secondary resources on cache reads |
299303

‎operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,11 @@ default Metrics getMetrics() {
251251
* pool of platform threads anymore. Since virtual threads are cheap, those limits can be set
252252
* considerably higher than what would be reasonable for platform threads.
253253
*
254-
* <p>Requires Java 21 or later at runtime. When enabled on an older JVM, a warning is logged and
255-
* platform threads are used, so that the same configuration works regardless of the Java version
256-
* the operator runs on.
254+
* <p>Officially supported on Java 25 or later. Virtual threads exist as of Java 21 and are used
255+
* there as well, but before Java 25 a virtual thread pins its carrier thread while inside a
256+
* {@code synchronized} block, which <a href="https://openjdk.org/jeps/491">JEP 491</a> removed in
257+
* Java 25. On a JVM without virtual threads at all, a warning is logged and platform threads are
258+
* used, so that the same configuration works regardless of the Java version the operator runs on.
257259
*
258260
* <p>Note that this only affects the executors created by the framework: a custom {@link
259261
* ExecutorService} provided through {@link #getExecutorService()} or {@link

‎operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public ConfigurationServiceOverrider withWorkflowExecutorService(
122122

123123
/**
124124
* Makes the framework run the tasks it executes concurrently on virtual threads instead of
125-
* platform threads. Requires Java 21 or later at runtime, see {@link
125+
* platform threads. Officially supported on Java 25 or later, see {@link
126126
* ConfigurationService#useVirtualThreads()} for the details.
127127
*
128128
* @param useVirtualThreads {@code true} to use virtual threads

‎operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/VirtualThreads.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ static boolean shouldUse(boolean requested) {
8989
if (UNSUPPORTED_WARNING_LOGGED.compareAndSet(false, true)) {
9090
log.warn(
9191
"Virtual threads were requested but are not supported by the JVM in use (Java {}, Java 21"
92-
+ " or later is required). Falling back to platform threads.",
92+
+ " or later is required, Java 25 or later is officially supported). Falling back to"
93+
+ " platform threads.",
9394
Runtime.version().feature());
9495
}
9596
return false;
@@ -99,7 +100,8 @@ static boolean shouldUse(boolean requested) {
99100
static ExecutorService newVirtualThreadPerTaskExecutor() {
100101
if (!isSupported()) {
101102
throw new OperatorException(
102-
"Virtual threads are not supported by the JVM in use, Java 21 or later is required");
103+
"Virtual threads are not supported by the JVM in use, Java 21 or later is required"
104+
+ " (Java 25 or later is officially supported)");
103105
}
104106
try {
105107
return (ExecutorService) NEW_VIRTUAL_THREAD_PER_TASK_EXECUTOR.invokeExact();

‎sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageOperator.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ public class WebPageOperator {
4040
public static void main(String[] args) throws IOException {
4141
log.info("WebServer Operator starting!");
4242

43-
Operator operator = new Operator(o -> o.withStopOnInformerErrorDuringStartup(false));
43+
Operator operator =
44+
new Operator(
45+
o -> o.withStopOnInformerErrorDuringStartup(false).withUseVirtualThreads(true));
4446
String reconcilerEnvVar = System.getenv(WEBPAGE_RECONCILER_ENV);
4547
if (WEBPAGE_CLASSIC_RECONCILER_ENV_VALUE.equals(reconcilerEnvVar)) {
4648
operator.register(new WebPageReconciler());

0 commit comments

Comments
 (0)