JDK 21 is Java SE 21, JSR 396, generally available on 19 September 2023. Vendors treat it as a long-term support release. Virtual threads, pattern matching for switch, record patterns, and sequenced collections are final. String templates, scoped values, structured concurrency, unnamed patterns, and unnamed classes are previews. The existing Java 21 example and the concurrency chapter stay the detailed sources.
How to read the status
Final. The change shipped in this release as a permanent part of that release.
Preview. It can be tried with --enable-preview. A preview is not a permanent language or API guarantee.
Incubator. An incubator API is not a supported standard API. It can change or be removed.
Language
Virtual Threads
JEP 444 · Final · Language
A virtual thread is a lightweight thread for blocking I/O. The JVM schedules many of them onto a smaller set of platform threads.
Preview in Java 19 (JEP 425) and Java 20 (JEP 436).
Also in this release: deprecation of the Windows 32-bit x86 port (JEP 449) and preparation to disallow dynamic agent loading (JEP 451).
Examples
versions6Java21Features.javaJava 21 example · Requires Java 21Virtual threads, record patterns, pattern matching for switch, and sequenced collections, in their Java 21 final form. String templates, structured concurrency, and scoped values were previews and are not shown.
concurrency6VirtualThreadsDemo.javaJava 21 example · Requires Java 21Virtual threads in the concurrency chapter. Thread.ofVirtual is the final Java 21 API. In Java 21 a virtual thread can stay pinned inside synchronized; Java 24 changed that.
advconcurrency7StructuredConcurrency.javaStable demo; Java 25 preview API is only in the comment · Requires Java 8The main method uses CompletableFuture and runs without --enable-preview. The comment shows the Java 25 preview API: StructuredTaskScope.open with a Joiner. JEP 505 is still a preview.
Since Java 17, this release finalizes virtual threads, switch patterns, and record patterns, and it adds sequenced collections. Structured concurrency, scoped values, string templates, unnamed variables, and unnamed classes remain previews. The Java 21 source file is unchanged and does not demonstrate the preview APIs.
Sources. General availability, JSR 396, and the JEP list: OpenJDK JDK 21. The example file versions6Java21Features.java is unchanged. OpenJDK JDK 21 (leaves JavaMastery)