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:
-
Inventory. For each service: the JDK version, flags, the Spring Boot version (Boot 3 requires Java 17+ and brings the
javax→jakartachange), and libraries that manipulate bytecode (Lombok, Mockito, ByteBuddy, ASM, agents).jdeps --jdk-internalsshows use of internal APIs. -
Pilot. I pick the most typical service, go through the whole path and document the problems found.
-
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.
-
Waves. With a canary, comparing the metrics after each wave.
Typical JVM-side pitfalls:
- Removed flags: CMS,
-XX:+UseConcMarkSweepGC, somePrintGC*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 throwInaccessibleObjectException. 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
synchronizedthe 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.
Sign up to mark studied questions and save your progress.