java

Java 12 Features (GC Saga continues)

It was released on March 19, 2019. It’s a non LTS release. Here’s an overview of the most relevant updates for developers.

Switch Expressions

It has passed a long time since the last update to switch statement, more specifically the switch on strings in JDK 7. Five versions later we have a new update.

switch (day) {
    case MONDAY,TUESDAY,WEDNESDAY,THURSDAY, FRIDAY ->
        System.out.println("Need to work! Yuck!");
    case SATURDAY, SUNDAY ->
        System.out.println("Weekend! To the pub!");
}

Shenandoah GC

Of course. It seems that every new release comes with a new implementation of GC. This is experimental like the rest though. It strives to be a low pause GC. It was developed by RedHat so its not part of the openjdk distributable. The main idea is that the GC tries to run concurrently more threads for collection, so any remaining for should be small and that means short pauses. In addition to the CMS and G1 it run also the compaction concurrently. It’s suitable for applications that need to be responsive. It has a SLA that guarantee response times of 10-500ms per application. More on this here.

-XX:+UnlockExperimentalVMOptions
-XX:+UseShenandoahGC

G1 GC Improvements

Before 12, when performing GC the G1 selects a collection of garbage and then goes through it collection every referenced object without stopping. This was improved in the sense that it splits the initial collection into a mandatory and optional part and it goes through the optional part only if it has enough time. Another problem that was solved is the return of the heap to the memory. Before 12 this was happening only when it was set to run concurrently or the GC was full. Now it’s returning the memory to the operation system by triggering a concurrent cycle during periods on inactivity.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.