Volatile — If field is declared as volatile in Java, every thread accessing the field will read the current value, i.e value from the main memory and not from the cache.

Multi-Core CPU

In today’s word, we use computers with multi-core CPU, which have capacity to execute multiple tasks/program in parallel. Many…

Singleton Pattern : Define a class that has only one Instance.

Let’s try creating Thread Safe Singleton pattern.

1) Simple Singleton pattern (Non Thread Safe)

public class Singleton {
private static Singleton instance;
private Singleton() {}

public static Singleton getInstance(){
if(instance == null)
{
instance = new Singleton();
}
return instance;
}
}

Sounds perfect right, We…

Jainil Gada

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store