1package com.journaldev.designpatterns;
2
3public class ASingleton {
4
5 private static volatile ASingleton instance;
6 private static Object mutex = new Object();
7
8 private ASingleton() {
9 }
10
11 public static ASingleton getInstance() {
12 ASingleton result = instance;
13 if (result == null) {
14 synchronized (mutex) {
15 result = instance;
16 if (result == null)
17 instance = result = new ASingleton();
18 }
19 }
20 return result;
21 }
22
23}
24