Ace8 is the modernization practice of AceMQ.24/7 support from AceMQ after go-live
Book an Assessment

Guide

Java 21 features, read from a legacy upgrade point of view.

Most lists tell you what is new. This one tells you which features you can adopt on day one, which you can ignore and which change how you run production.

AceMQ engineering team3 min readEngineer-reviewed

The short answer

Java 21, released September 2023, is an LTS release. Its headline features are virtual threads (JEP 444), record patterns (JEP 440), pattern matching for switch (JEP 441), sequenced collections (JEP 431) and generational ZGC (JEP 439). For a legacy upgrade, virtual threads and the garbage collector change operations. The rest are optional code improvements.

01Triage

Which Java 21 features do you adopt during the upgrade?

Upgrading the runtime and adopting a language feature are separate jobs. Do the first now and the second later. The upgrade itself is described on the Java upgrade page.

FeatureJEPTouchesAdopt during upgrade?
Virtual threads444Runtime and concurrency designNo. Test first, adopt per service
Generational ZGC439Operations and tuningOptional. Benchmark on your workload
Record patterns440Source codeNo. Use in new code
Pattern matching for switch441Source codeNo. Use in new code
Sequenced collections431Library APIOptional. Small, safe additions
Dynamic agent loading warning451Tools and agentsYes. Check your APM and test agents

02Concurrency

Virtual threads: what changes and what does not

Virtual threads are lightweight threads managed by the JVM. They let a server hold many blocked requests without one operating system thread each. Code written in the plain blocking style scales better without moving to reactive libraries.

They do not make CPU-bound code faster. They help when threads mostly wait on a database, a file or another service.

Two checks matter in a legacy codebase. First, code that holds a synchronized lock while blocking could pin the carrier thread in Java 21; that was relieved in a later release. Second, thread-local caches sized for a small pool can grow when you have many thousands of virtual threads. A connection pool is still a hard limit: virtual threads do not create more database connections.

Planning this for your estate? Get a fixed scope and price first.

03Language

Record patterns and pattern matching for switch

Pattern matching for switch lets a switch test the type of a value and bind it in one step. Record patterns take that further and unpack a record into its parts. Together they replace chains of instanceof checks and casts.

A legacy application gets nothing from these until someone rewrites code to use them. Recipes can find simple instanceof chains, but a person should choose where the new form reads better. Treat this as cleanup after the upgrade, not part of it.

04Library

Sequenced collections

Sequenced collections add methods such as getFirst, getLast and reversed to collections that have a defined order, including List, Deque and LinkedHashSet. Before Java 21 the way to get the last element differed by type.

One compatibility note: adding methods to interfaces can clash with methods in your own subclasses or in libraries that already define getFirst or getLast. The compiler tells you. It is a small but real source of build errors when moving to 21.

05Operations

Generational ZGC

ZGC is a low-pause garbage collector. In Java 21 it gained a generational mode, which collects young objects more often and can reduce the memory and CPU cost of collection. In Java 21 you enable it with a flag; later releases changed the default.

Do not switch collectors because a list says so. Measure pause time, throughput and memory on a copy of your own workload, against the collector you run now.

06Our test

What are we testing on a real upgrade?

We are running a sample-repository upgrade to Java 21 with OpenRewrite recipes, AI-assisted tools and engineer review. We will record which compile errors, runtime flags and test failures appear and which of them the recipes fixed. We are running this test; results will be published here.

07Next step

How does Ace8 help?

Ace8 is the AI-assisted application modernization practice of AceMQ. We move estates onto a supported Java version and leave feature adoption for the teams that own the code.

To see what a Java 21 upgrade would involve for your applications, start with the modernization assessment. See also Java 25 LTS if you are choosing between the two.

FAQ

Frequently asked.

Something else on your mind? Ask an engineer.

Virtual threads, record patterns, pattern matching for switch, sequenced collections and generational ZGC are the headline features.

Start here

Know the cost before anything moves.

A fixed-price assessment gives you the inventory, the risk score and a phased plan. Scope and cost are fixed before the migration starts.

Get in touch

Talk to a modernization engineer

Tell us what you run today. An engineer, not a sales script, replies within one business day.

305-204-2607info@ace8.io

66 W. Flagler St. 9th Floor
Miami, FL 33130

What are you moving off? *

Fixed price. Scope and cost before any migration starts.