// 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 SingletonLazyness2 {
	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 someInstanceMethod() {
			System.out.println("SingletonOne someInstanceMethod " + System.currentTimeMillis());
		}
		public static void someStaticMethod() {
			System.out.println("SingletonOne someStaticMethod " + 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 someInstanceMethod() {
			System.out.println("SingletonTwo someInstanceMethod " + System.currentTimeMillis());
		}
		public static void someStaticMethod() {
			System.out.println("SingletonTwo someStaticMethod " + System.currentTimeMillis());
		}
	}
	public static void main(String[] args) throws InterruptedException {
		SingletonOne.someStaticMethod();
		SingletonTwo.someStaticMethod();
		Thread.sleep(1000);
		SingletonOne.getInstance().someInstanceMethod();
		SingletonTwo.getInstance().someInstanceMethod();
	}

}
