Posts

Showing posts from April, 2023

Java 10 Features

  Java 10 Features: Core library changes:  Optional.orElseThrow : A new method orElseThrow has been added to the Optional class. It is synonymous with and is now the preferred alternative to the existing get method. APIs for Creating Unmodifiable Collections : The List.copyOf , Set.copyOf, and Map.copyOf methods create new collection instances from existing instances. New methods toUnmodifiableList, toUnmodifiableSet, and toUnmodifiableMap have been added to the Collectors class in the Stream package. These allow the elements of a Stream to be collected into an unmodifiable collection. c.System Property to Disable JRE Last Usage Tracking  Local variable ‘var’ type inference Parallel Full GC for G1  Improve docker container detection and resource configuration usage Allow more flexibility in selecting Heap % of available RAM , Heap Allocation on Alternative Memory Devices Thread-Local Handshakes Removals:  Removal of Support for Using Old LookAndFeel ...

Volatile

  Volatile: When a field is declared as volatile, then the compiler and runtime are notified that the variable is shared. The volatile variable always returns the most recent write by any thread. Volatile variable performs no locking and will not block the thread, it makes lightweight synchronisation mechanism. When thread A writes to a volatile variable and thread B reads the same variable, then the value written is immediately available to thread B while reading. Writing a volatile variable is like exiting a synchronized block and reading a volatile variable is like entering a synchronized block. The volatile variable can only guarantee visibility . but locking can guarantee both visibility and atomicity. Volatile=Visibility Locking= Visibility & Atomicity     Explanation: Locks offer mutual exclusion and visibility Mutual Exclusion: It means only one thread at a time can hold a given lock and can use the shared data. Visibility: Its like ensuring that change...