Video in progress

How do you draw up a plan to move 30 services from Java 11 to Java 21, and what risks do you expect from the JVM side?

First I find all the problems on one pilot service, and then I migrate in waves with a common base image and a checklist. The main risks are removed flags, strong encapsulation, old libraries and changes in GC behavior.

📖 Answer

The plan has four stages:

  1. Inventory. For each service: the JDK version, flags, the Spring Boot version (Boot 3 requires Java 17+ and brings the javax → jakarta change), and libraries that manipulate bytecode (Lombok, Mockito, ByteBuddy, ASM, agents). jdeps --jdk-internals shows use of internal APIs.

  2. Pilot. I pick the most typical service, go through the whole path and document the problems found.

  3. Base image and CI. A new base image, and a parallel build with Java 21 in CI. Services whose tests are green join the queue.

  4. Waves. With a canary, comparing the metrics after each wave.

Typical JVM-side pitfalls:

  • Removed flags: CMS, -XX:+UseConcMarkSweepGC, some PrintGC* flags (replaced by unified logging). With an unknown flag the JVM won't start at all.
  • In JDK 16+ internal APIs are strongly encapsulated: old libraries that reach into sun.* with reflection throw InaccessibleObjectException. A temporary --add-opens, but the real fix is updating the library.
  • Biased locking was disabled in JDK 15 and later removed, so in old code with a lot of uncontended synchronized the difference may be noticeable.
  • G1's defaults and ergonomics have changed, so the memory profile will be different. GC log formats changed too, so update log parsers and dashboards.
  • The Security Manager is deprecated, and TLS and cryptography defaults have been tightened.

Always have a rollback plan: keep the old image tag, so you can go back with a single configuration change.