Files
spring-async-demo/virtual-threads-benchmark/src/test/java/com/ankurm/vthreads/ScopedValueTest.java
T
asmhatre f506b01389 Add virtual-threads-benchmark: re-run Spring Boot 4.1 / JDK 25 benchmarks, JEP 491 pinning fixed
Companion module for the rewritten post 'Virtual Threads on Spring Boot 4.1: The Benchmarks,
Re-Run, and the Pinning Advice That Expired', retitled and re-benchmarked on Boot 4.1.1 /
JDK 25.0.4.1 (the original post was written against Boot 3.4 / JDK 21). Covers: I/O-bound and
CPU-bound throughput (platform vs virtual threads, including a JIT-warmup benchmarking bug this
build caught and fixed), JEP 491 proof that synchronized no longer pins a virtual thread's
carrier across a blocking call as of JDK 24 (obsoleting the old avoid-synchronized advice),
proof that -Djdk.tracePinnedThreads=full is inert on JDK 25, and JEP 506's finalized ScopedValue
API (JDK 25 GA, no --enable-preview, and a different shape than the old preview API). Kept as
its own module rather than a new top-level repository, alongside the existing async/ module,
which already has a stronger dual-JDK JEP 491 proof that this module's docs cross-link to
instead of duplicating.
2026-09-18 08:52:59 +00:00

28 lines
999 B
Java

package com.ankurm.vthreads;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Confirms the finalized JDK 25 ScopedValue API (JEP 506) compiles and runs with no
* --enable-preview flag, and that ScopedValue.where(...).call(...) actually threads the value
* through to a method called from inside the scope. Output:
* docs/output/03c-scoped-value-finalized.txt.
*/
class ScopedValueTest {
@Test
void whereRunThreadsContextThroughToCalledMethod() {
Transcript t = Transcript.start("03c-scoped-value-finalized.txt",
"ScopedValue (JEP 506, finalized JDK 25), JDK " + System.getProperty("java.version"));
String result = ScopedValueDemo.runWithContext("req-42");
t.line("ScopedValue.where(CTX, ctx).call(ScopedValueDemo::processRequest) -> " + result);
t.line("no --enable-preview flag used on this run");
t.save();
assertThat(result).isEqualTo("handled req-42");
}
}