Return to Snippet

Revision: 55443
at February 7, 2012 07:35 by kajinka13


Initial Code
public class Singleton {
	private static Singleton istance = null; // riferimento all'istanza

	private Singleton() { } // costruttore

	public static Singleton getIstance() {
		if(istance==null)
			synchronized(Singleton.class) {
				if(instance == null)
					istance = new Singleton();
				}
		return istance;
	}

	public void metodo() { ... }
	....
}

...
Singleton sg1 = Singleton.getIstance(); // Crea l'istanza
sg1.metodo();
...

Initial URL

                                

Initial Description
Classe Singleton

Initial Title
Classe Singleton

Initial Tags
java

Initial Language
Java