Backend Development 32 min read

Practical Guide to Upgrading Java 8 to JDK 11 with G1 GC: Benefits, Steps, and New Features

The article provides a hands‑on migration guide for moving an internal gateway service from Java 8 to JDK 11 with the G1 garbage collector, detailing a checklist of tool and dependency updates, showcasing up to 105 % performance gains, outlining new language features, virtual‑thread usage, and best‑practice recommendations for a smooth, cost‑effective upgrade.

DaTaobao Tech
DaTaobao Tech
DaTaobao Tech
Practical Guide to Upgrading Java 8 to JDK 11 with G1 GC: Benefits, Steps, and New Features

This article presents a practical migration of an internal gateway service from JDK 8 to JDK 11 with the G1 garbage collector, summarizing performance gains, cost savings, and a step‑by‑step upgrade guide.

Performance improvements : SPECjbb2015 benchmarks show that JDK 11 + G1 outperforms JDK 8 + CMS with a 17% increase in max‑jOPS throughput and a 105% increase in critical‑jOPS. GC metrics also improve – YGC frequency drops from 7 to 4 times/min (‑43%) and average pause time from 48 ms to 25 ms (‑48%).

Upgrade checklist :

Upgrade development tools (IntelliJ 2018.2+, Eclipse Photon 4.9RC2, Maven 3.5.0, Gradle 5.0).

Update the JDK installation (openjdk.org) and Tomcat version.

Replace removed Java EE modules with explicit dependencies (e.g., <dependency><groupId>javax.annotation</groupId><artifactId>javax.annotation-api</artifactId><version>1.3.2</version></dependency> ).

Upgrade Spring to 5.x (or later) because Spring 4.x only supports up to JDK 8.

Adjust GC parameters: replace -Xloggc:file with -Xlog:gc:file , remove deprecated flags such as -XX:+PrintGCDetails .

Key Java language changes (9‑19) :

Module system (JPMS) – requires explicit requires statements.

Immutable collection factories ( List.of() , Set.of() , Map.of() ).

Var for local type inference (Java 10) and enhanced var usage in lambda parameters (Java 11).

New String methods: isBlank() , lines() , repeat(int) , strip() family.

Stream API extensions: takeWhile , dropWhile , ofNullable , enhanced iterate .

Interface private methods (Java 9) and private static methods.

Pattern matching for instanceof (Java 16) and for switch (Java 17‑20).

Text blocks (Java 15) for multi‑line strings.

Virtual threads (Java 19 preview) provide lightweight concurrency, allowing millions of concurrent tasks with simple Thread API usage. Example:

try (var executor = Executors.newVirtualThreadPerTaskExecutor()) { IntStream.range(0, 10_000).forEach(i -> executor.submit(() -> { Thread.sleep(Duration.ofSeconds(1)); return i; })); }

Best practices :

Do not pool virtual threads – create a new one per task.

Avoid ThreadLocal in virtual threads.

Prefer ReentrantLock over synchronized blocks to prevent blocking platform threads.

The article also includes detailed tables comparing heap size, object counts, and GC statistics before and after the upgrade, as well as a full Log4jConfigListener implementation for legacy logging migration.

JavaPerformanceSpringG1GCUpgradeJDK11VirtualThreads
DaTaobao Tech
Written by

DaTaobao Tech

Official account of DaTaobao Technology

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.