Stop the world phase

Garbage Collection literally stops the world.

When a GC occurs in young generation space, it is completed quickly as the young generation space is small.

Young generation space is the space where newly instantiated objects are stored. Internally, this space has two survivor spaces which are used when GC occurs and the objects which still have references are shifted to a survivor space. If an object survives many cycles of GC, it is shifted to old generation space.

Problem is when GC occurs in Old generation space which contains long lived objects. This space uses a lot more memory than the young generation and when GC occurs in old generation, it literally halts all the requests made to that JVM process.

So, the world literally stops !!

Why Java 8 ?

In simple words java 8 allows us to write code more precisely and concisely, which is better than writing verbose code in the java versions prior to java 8.

Example: Let’s sort a collection of cars based on their speed.

Java versions prior to java 8 :

Collections.sort(fleet, new Comparator() {
  @Override
  public int compare (Car c1, Car c2) { 
  return c1.getSpeed().compareTo(c2.getSpeed());
  }
}

Instead of writing a verbose code like above, using java 8 we can write the same code as:

Java 8 :

fleet.sort(Comparator.comparing(Car::getSpeed));

The above code is more concise and could be read as “sort fleet comparing Car’s speed”.

So why write a boilerplate code which is not related to the problem statement. Instead you can write concise code which is related to the problem statement and has SQL like readability.