Skip to content

Instantly share code, notes, and snippets.

@laaptu
Created March 3, 2016 05:21
Show Gist options
  • Save laaptu/2ee0e9fa219abd91b44e to your computer and use it in GitHub Desktop.
Save laaptu/2ee0e9fa219abd91b44e to your computer and use it in GitHub Desktop.
Creating a singleton
public class DbManager {
static volatile DbManager singleton = null;
private DbManager() {
}
public static DbManager getInstance() {
if (singleton == null) {
synchronized (DbManager.class) {
if (singleton == null)
singleton = new DbManager();
}
}
return singleton;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment