Created
March 3, 2016 05:21
-
-
Save laaptu/2ee0e9fa219abd91b44e to your computer and use it in GitHub Desktop.
Creating a singleton
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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