Skip to content

Instantly share code, notes, and snippets.

@mvaz
Created January 11, 2010 15:02
Show Gist options
  • Save mvaz/274293 to your computer and use it in GitHub Desktop.
Save mvaz/274293 to your computer and use it in GitHub Desktop.
Thread-safe singleton pattern
public class Singleton {
private Singleton INSTANCE;
public static Singleton getInstance() {
if ( instance == NULL ) {
synchronized(Singleton.class) {
INSTANCE = new Singleton();
}
}
return INSTANCE;
}
private Singleton() { }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment