Possible Duplicate:
What is an efficient way to implement a singleton pattern in Java?
I am new to design pattern and in learning phase. Recently I learned about Singleton pattern and I looked around our company's code where I work. I have found the following code snippet which looks incorrect according to the Singleton rules i.e we should not synchronize a method but sunchronize a block. And thread should always check whether the "ïnstance" variavle's value is null or not before entering the block. Is my understanding is correct or there is some logic to code in following manner?
public class CustomLogger {
private static CustomLogger instance;
private CustomLogger(){
some code here....
}
public static synchronized CustomLogger getInstance(){
if (instance == null){
instance = new CustomLogger();
}
return instance;
}
}