Singleton: Difference between revisions

Line 300:
 
===Thread-safe===
Double-checked locking
 
only use with Java 1.5+
<java>
class Singleton
{
private static Singleton myInstance;
public static synchronized Singleton getInstance()
{
if (myInstance == null)
myInstance = new Singletonsynchronized(this);
if (myInstance == null)
myInstance = new Singleton();
 
return myInstance;
Anonymous user