I came across a singleton class {lazy initialization}. The code is as below
// Singleton reference for this class
private static volatile FileProperties INSTANCE = null;
public static FileProperties getInstance() {
if (INSTANCE == null) {
synchronized (FileProperties.class) {
if (INSTANCE == null) {
INSTANCE = new FileProperties();
}
}
}
return INSTANCE;
}
My question is what is the benefit we are getting by making INSTANCE as volatile Since we already taking care of thread safety by synchronized. Is there any benefit of volatile in this scenario ?