Java 11 LTS: Migrating to the Modular HTTP Client and G1 GC Default Upgrades

Migrating to the next LTS. We explore HttpClient APIs, G1 GC improvements, and the removal of Java EE modules.

VP
SHIVAM ITCS
·12 September 2018·10 min read·1 views

Technical Overview & Strategic Context

Following the modularization in Java 9, Oracle established a rapid release cycle: a new version every six months, with a Long-Term Support (LTS) release every three years. The launch of Java 11 in September 2018 marks the first LTS release under this new model. This version stabilizes the platform by removing deprecated Java EE and CORBA modules, improving the default G1 Garbage Collector, and introducing the standardized HttpClient API (JEP 321), replacing the obsolete HttpURLConnection.

Architectural Principle: Transition enterprise systems to Java 11 LTS to leverage modern security protocols and improved garbage collection. Replace HttpURLConnection with the non-blocking HttpClient.

Core Concepts & Architectural Blueprint

Java 11 removes legacy modules (like JAXB and JAX-WS), requiring developers to declare these dependencies explicitly in Maven or Gradle configurations. The new HttpClient (java.net.http) supports HTTP/2, WebSockets, and asynchronous requests natively. The G1 Garbage Collector was updated to improve memory reclaiming and reduce pause times on large heaps.

Performance & Capability Comparison

Java FeatureJava 8 LTS StandardJava 11 LTS StandardMigration Impact
HTTP ClientBlocking HttpURLConnection APINon-blocking HttpClient (HTTP/2 support)Speeds up asynchronous API calls
JDK StructureMonolithic runtime filesModular JDK modules (Project Jigsaw)Reduces deployment image sizes
Garbage CollectorParallel GC default settingsUpdated G1 Garbage Collector defaultReduces GC pause times on server nodes

Implementation & Code Pattern

To query external APIs asynchronously using the Java 11 HttpClient, follow these steps:

  • Initialize an HttpClient instance specifying HTTP version targets.
  • Build HttpRequest configuration structures passing destination URIs.
  • Send the request asynchronously using the sendAsync method.
  • Handle response payloads asynchronously using CompletableFuture chains.
javacode
// Async HTTP API request using Java 11 HttpClient (2018)
package in.shivamitcs.portal.services;

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.concurrent.CompletableFuture;

public class AnalyticsClient {
    private final HttpClient client = HttpClient.newBuilder()
            .version(HttpClient.Version.HTTP_2)
            .build();

    public CompletableFuture<String> fetchReport(String reportId) {
        var request = HttpRequest.newBuilder()
                .uri(URI.create("https://api.shivamitcs.in/reports/" + reportId))
                .GET()
                .build();

        // Send request asynchronously, returning a CompletableFuture
        return client.sendAsync(request, HttpResponse.BodyHandlers.ofString())
                .thenApply(HttpResponse::body);
    }
}

Operational Governance & Future Outlook

Java 11 LTS updated the Java ecosystem by removing legacy packages and standardizing modern APIs like HttpClient. Upgrading database and microservice runtimes to Java 11 helps improve performance and security.

VP
Vijay Paliwal
Founder, SHIVAM ITCS · 18+ years enterprise & AI engineering
MCA · Ex-HiveGPT USA · Ex-Social27 Seattle
Java 11 LTS: Migrating to the Modular HTTP Client and G1 GC Default Upgrades | SHIVAM ITCS Blog | SHIVAM ITCS