Virtual thread API migration failures from JDK 19/20 preview to JDK 21 final
0 reputation · 27 Feb 2023, 03:23 UTC
Goal: diagnose why code that compiled and ran with the preview virtual thread API in JDK 19 or JDK 20 fails when compiled or executed on JDK 21, where virtual threads are finalized and the API has changed.
Constraints: the code may use preview‑only imports (jdk.incubator.concurrent), preview‑only constructors, and custom scheduler implementations that relied on preview‑only classes; there is uncertainty about which preview methods were removed, what their replacements are, and how refined thread‑pinning behavior in the final release affects libraries that synchronize or call native code.
End with specific questions:
- Which preview‑only virtual‑thread methods (e.g., Thread.startVirtualThread) were removed or renamed in the final API, and what are the recommended replacements?
- What adaptation is needed for custom scheduler code to work with the final virtual‑thread API, especially regarding removal of the preview‑only FiberScheduler interface?
- What adjustments are needed to avoid thread‑pinning warnings when using the final virtual‑thread API with libraries that hold monitors or invoke native methods?