Package Singleton mode;
Public class SingletonPattern {
Private volatile static SingletonPattern singletonPattern = null;
Private SingletonPattern (){
}
Public static SingletonPattern getSingletonPattern (){
/**
* <1> In Thread synchronized
*/
If (singletonPattern = null ){
Synchronized (SingletonPattern. class ){
If (singletonPattern = null ){
SingletonPattern = new SingletonPattern ();
}
}
}
/**
* <2>
*/
SingletonPattern = SingletonPatternInstance. instance;
Return singletonPattern;
}
Private static class SingletonPatternInstance {
Private static SingletonPattern instance = new SingletonPattern ();
}
Public void say ()
{
System. out. println ("hello world ");
}
/**
* @ Param
*/
Public static void main (String [] args ){
// TODO Auto-generated method stub
SingletonPattern. getSingletonPattern (). say ();
}
}
This article is from the "feisha" blog