A Singleton is a quite simple concept, that can be implemented this way:

public class MySingleton {
  private static MySingleton instance = null;
  /** Private constructor. */
  private MySingleton() {
    // initialization...
  }
  public static MySingleton getInstance() {
    if (instance == null) {
      instance = new MySingleton();
    }
    return instance;
  }
  // other methods
}

But what about multiple threads call getInstance() simultaneously? (altro…)

Un Singleton è un concetto abbastanza semplice, che si può implementare così:

public class MySingleton {
  private static MySingleton instance = null;
  /** Private constructor. */
  private MySingleton() {
    // initialization...
  }
  public static MySingleton getInstance() {
    if (instance == null) {
      instance = new MySingleton();
    }
    return instance;
  }
  // other methods
}

Ma cosa succede quando più thread chiamano getInstance() contemporaneamente? (altro…)