public class Singleton
{
  // methods and attributes for Singleton pattern
  
  private Singleton() { // private constructor
    initGlobals();
  }

  static private Singleton _instance; // defaults to null

  // Singleton getter utilizing Double Checked Locking pattern
  public static Singleton getInstance() {
  if (_instance == null) {
    synchronized(Singleton.class) {
      if (_instance == null)
        _instance = new Singleton();
    }
  }
  return _instance;
  }

  // methods and attributes for global data
  
  // constructor for global variables
  private void initGlobals() { 
    globalInteger = 5;
    idCounter = 0;
  }
  
  // keep global data private
  private int globalInteger;
  
  public int getGlobalInteger() { 
    return globalInteger; 
  }
  
  public void setGlobalInteger(int value) {
    globalInteger = value;
  }

  private int idCounter;
  
  synchronized public int getUniqueID() { 
    idCounter++;
    return idCounter; 
  }
  
}

