Search This Blog

Tuesday 3 July 2018

Parallel / Old GC, CMS, G1 GC - Java 7, Meta space , HashMap enhancement , streams- Java 8

Parallel / Old GC, CMS, G1 GC - Java 7, Meta space , HashMap enhancement  streams- Java 8


Types of garbage collectors in Java - serial GC - Jvm uses during garbage collection & mark and delete objects

Parallel GC similar to serial GC but multiple threads are used to speed up garbage collection & n number of threads based on young generation and one thread for old generation

Parallel Old GC - similar to parallel GC but it has n number of threads for young generation and n number of threads for old generation

Concurrent Mark Sweep -  these will do garbage collection for old generation; tries to minimize the pause which happens garbage collection; and uses concurrent mechanism

G1 GC - It is introduced to replace CMS GC. It is a parallel concurrent & incrementally compacting low pause collector. There is no concept of old and young  generation objects. It divides the space inside the heap into multiple equally sized regions and whenever there is grabage collection involved it first collects the region which have lesser live data.

G1 GC - Jvm 7 and above versions supports.
Gc will do Mark , Delete and Compacting.

Mark: Initially GC marks all objects in the heap reachable or unreachable.

Delete: GC deletes the all unreachable objects in the heap.

Compacting: GC deleted all unreachable objects from various memory locations so it arranges the all the reachable objects in side by side memory locations sequentially.

Meta space : PermGen space replaced with meta space in java 8. It is allocated by OS so there is no OutOfMemoryException from java 8 onwards. But there is drawback to take whole server space. Different sizes can be specified for meta space like java heap space.

HashMap 8 enhancement - we all know hashmap contains table and maintains objects in the linked list form for collision of hash code for different keys for same bucket. But in java 8 if objects crossed threshold value  in the hash bcket, then automatically arranges linked list objects into balanced tree format to improve performance.

Jav8 streams - There are two types of streams introduced in it such as sequential stream and second one is parallel stream. Through those java supports functional programing.

Sequential stream - which creates stream object for   for collection elements and processes one thread.

Parallel streams:  This uses Fork Join Thread Pool Framework to processes collection object elements. Collection elements divided into sub tasks and fork thread pool threads executes the sub tasks and joins the results of all subtasks and finally sends back the result. It maximises the cpu cores utilisation and maximises the throughput.
These improves performance drastically of the application if ur playing with huge amount of data.



Container creates thread object for dispatcherservlet which is extended from HttpServlet and all singleton beans shared among all threads. Note no threads will be created for singleton object.

No comments:

Post a Comment