This file contains 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 static synchronized Singleton getInstance() { | |
// checks if instance already created | |
if (Instance == null) { | |
// if not create an instance | |
Instance = new Singleton(); | |
} | |
// return the created instance on all subsequent calls | |
return Instance; | |
} |
This file contains 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 Singleton { | |
// holds created instance of the singleton class | |
private static Singleton Instance = new Singleton(); | |
// private constructor | |
private Singleton () {} | |
public static Singleton getInstance() { | |
// return the created instance on all subsequent calls | |
return Instance; |
This file contains 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 Singleton { | |
private volatile static Singleton Instance(); | |
private Singleton () {} | |
public static Singleton getInstance() { | |
if (Instance == null) { | |
synchronized (Singleton.class) { | |
if (Instance == null) { |
OlderNewer