Cloud Software Engineering and Architecture

Why Java 21 is built to scale

Why Java 21 is built to scale
Photo by Tomas Williams / Unsplash

Java 21 entered the release candidate state in the recent days. This means that no further changes are expected. Occasional bug fixes may arise. This is a perfect time to take a first look and see what is new and relevant for cloud engineers. In this issue, I will provide some basic guidance around the new features and a high-level overview.

Theme: Throughput and scale

These are the two words that come to mind when looking at the recent features. Project Loom making one of the biggest contributions to the current release. Reactive programming, as applied in Spring WebFlux, has served really well in the past and will stay relevant. However, for many cases where throughput became a challenge, virtual threads will provide some relieve. We will go into details in the following episodes.

What is not covered here

I will not cover language syntax features like switch statement patterns, etc. Not that these are not useful features. These are excellent, but they are well documented in numerous articles. Here, I dedicate my efforts to making sense of the runtime aspects and what impact they have on your existing workloads and future system design.

Covered features

Covered in the series because these features will be relevant:

Virtual Threads will increase throughput and allow optimal resource utilisation. Structured concurrency (preview) complements virtual threads and allows cancellation of parallel tasks – which will become more relevant with virtual threads. Scoped values (preview) are relevant in light of the adoption of virtual threads as well. They allow for more efficient memory allocation at scale. This will be an improvement for thread-local variables. Generational ZGC is a new garbage collection algorithm that efficiently discards short-lived objects.

Furthermore, we will look at the Key Encapsulation Mechanism API. It provides a standardised API to implement the key encapsulation mechanism. We will elaborate why this feature is relevant and in which scenarios you might need it.

Other features that I will cover in the series because they might become interesting are String Templates and the Vector API.

Disclaimer: 21 is not a LTS version

While the new version comes with a lot of nice new features, be aware that this is no long-term-support version. What does this mean? If you are relying on OpenJDK 21, do not expect a party to be accountable for resolving any issues. However, you are lucky if you are using infrastructure services like Amazon Web Services. They usually offer maintained builds for OpenJDK. That distribution is called Amazon Corretto. You can find many other vendors on the Wikipedia page.

Subscribe to Benedikt Roth

Sign up now to get access to the library of members-only issues.
Jamie Larson
Subscribe