Skip to content

Instantly share code, notes, and snippets.

@TonnyXu
Created March 1, 2010 08:40
Show Gist options
  • Save TonnyXu/318209 to your computer and use it in GitHub Desktop.
Save TonnyXu/318209 to your computer and use it in GitHub Desktop.
public class Singleton5 {
private static volatile Singleton5 INSTANCE = null;
private Singleton5(){
if (null != INSTANCE){
throw new IllegalArgumentException("Already instantiated.");
}
}
public static Singleton5 getInstance(){
if (null == INSTANCE){
synchronized (Singleton5.class) {
if (null == INSTANCE){
INSTANCE = new Singleton5();
}
}
}
return INSTANCE;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment