// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
public class SingletonLazyness {
	public static class SingletonOne {
		private static SingletonOne instance = new SingletonOne();
		private SingletonOne() {
			System.out.println("SingletonOne ctor " + System.currentTimeMillis());
		}
		private static SingletonOne getInstance() {
			return instance;
		}
		public void someMethod() {
			System.out.println("SingletonOne someMethod " + System.currentTimeMillis());
		}
	}
	public static class SingletonTwo {
		private static SingletonTwo instance = null;
		private SingletonTwo() {
			System.out.println("SingletonTwo ctor " + System.currentTimeMillis());
		}
		private synchronized static SingletonTwo getInstance() {
			if(instance == null) {
				instance = new SingletonTwo();
			}
			return instance;
		}
		public void someMethod() {
			System.out.println("SingletonTwo someMethod " + System.currentTimeMillis());
		}
	}
	public static void main(String[] args) throws InterruptedException {
		System.out.println("Main starting " + System.currentTimeMillis());
		Thread.sleep(1000);
		SingletonOne.getInstance().someMethod();
		SingletonTwo.getInstance().someMethod();
	}
}
