27 lines
495 B
Java
27 lines
495 B
Java
class Singleton
|
|
{
|
|
private static Singleton myInstance;
|
|
public static Singleton getInstance()
|
|
{
|
|
if (myInstance == null)
|
|
{
|
|
synchronized(Singleton.class)
|
|
{
|
|
if (myInstance == null)
|
|
{
|
|
myInstance = new Singleton();
|
|
}
|
|
}
|
|
}
|
|
|
|
return myInstance;
|
|
}
|
|
|
|
protected Singleton()
|
|
{
|
|
// Constructor code goes here.
|
|
}
|
|
|
|
// Any other methods
|
|
}
|