What’s New in Java 24? Exploring Structured Concurrency, Shenandoah GC, and Stream Gatherers
Java 24 GA introduces 24 JEPs, including Structured Concurrency for safer parallelism, Shenandoah GC as a low‑pause collector, Stream Gatherers for custom stream operations, primitive pattern matching, virtual‑thread improvements, Unsafe warnings, and post‑quantum cryptography, all aimed at modernizing the platform.
Java 24 has been officially released as a GA version, bringing 24 JEPs that introduce major enhancements to the Java platform.
Structured Concurrency (JEP 499)
Structured Concurrency, previewed in JDK 21 and now in its fourth preview, groups concurrent tasks into a scoped unit, binding the lifecycle of child tasks to the scope and providing automatic resource management and centralized exception handling. It replaces manual thread management such as ExecutorService.shutdown(), preventing thread leaks.
Using StructuredTaskScope within a try‑with‑resources block ensures that all subtasks are cancelled or awaited when the scope ends.
Synchronize Virtual Threads without Pinning (JEP 491)
Virtual threads can now be used inside synchronized blocks without being pinned to a platform thread, greatly improving concurrency and throughput.
JDK 24 also drops support for Windows 32‑bit (x86) platforms because they cannot implement virtual threads.
Generational Shenandoah (JEP 404)
Shenandoah GC, the successor to G1, becomes a standard feature in JDK 24. It performs most GC work concurrently, including heap compaction, keeping pause times under 10 ms regardless of heap size.
Unlike G1, Shenandoah does not use a generational model; the heap is divided into regions that are managed independently based on object lifetimes.
Primitive Types in Patterns, instanceof, and switch (JEP 488)
Pattern matching now supports primitive types, reducing boxing/unboxing overhead and extending the capabilities of switch expressions.
switch (x.getStatus()) {
case 0 -> "okay";
case 1 -> "warning";
case 2 -> "error";
default -> "unknown status: " + x.getStatus();
}Stream Gatherers (JEP 485)
JEP 485 adds the Gatherer interface, allowing developers to define custom intermediate operations for the Stream API, enabling complex transformations such as windowed grouping and folding.
Stream.iterate(0, i -> i + 1)
.limit(8)
.gather(Gatherers.windowFixed(3))
.toList(); // [[0,1,2],[3,4,5],[6,7]] Stream.of(1,2,3,4,5)
.gather(Gatherers.fold(() -> 0, Integer::sum))
.forEach(System.out::println); // 15Unsafe Memory‑Access Warning (JEP 498)
The memory‑access methods of sun.misc.Unsafe have been deprecated since JDK 23 and will be removed in a future release. A warning encourages migration to standard APIs to avoid crashes, performance regressions, and security risks.
Quantum‑Resistant Cryptography (JEP 496 & 497)
Two JEPs introduce post‑quantum cryptography to the Java platform: a module‑lattice‑based key‑encapsulation mechanism (ML‑KEM) and a module‑lattice‑based digital signature algorithm (ML‑DSA), enhancing Java’s security against future quantum attacks.
Overall, while Java 24 brings many innovative features, it is not an LTS release, so upgrading can be deferred if stability is a priority.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Su San Talks Tech
Su San, former staff at several leading tech companies, is a top creator on Juejin and a premium creator on CSDN, and runs the free coding practice site www.susan.net.cn.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
