BAEL-7145
Bill Pugh Singleton implementation
This commit is contained in:
+15
@@ -0,0 +1,15 @@
|
||||
package com.baledung.billpugh;
|
||||
|
||||
public class BillPughSingleton {
|
||||
private BillPughSingleton() {
|
||||
|
||||
}
|
||||
|
||||
private static class SingletonHelper {
|
||||
private static final BillPughSingleton BILL_PUGH_SINGLETON_INSTANCE = new BillPughSingleton();
|
||||
}
|
||||
|
||||
public static BillPughSingleton getInstance() {
|
||||
return SingletonHelper.BILL_PUGH_SINGLETON_INSTANCE;
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package com.baledung.billpugh;
|
||||
|
||||
public class EagerLoadedSingleton {
|
||||
private static final EagerLoadedSingleton EAGER_LOADED_SINGLETON = new EagerLoadedSingleton();
|
||||
private EagerLoadedSingleton() {
|
||||
|
||||
}
|
||||
public static EagerLoadedSingleton getInstance() {
|
||||
return EAGER_LOADED_SINGLETON;
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.baledung.billpugh;
|
||||
|
||||
public class LazyLoadedSingleton {
|
||||
private static LazyLoadedSingleton lazyLoadedSingletonObj;
|
||||
|
||||
private LazyLoadedSingleton() {
|
||||
}
|
||||
|
||||
public static LazyLoadedSingleton getInstance() {
|
||||
if (null == lazyLoadedSingletonObj) {
|
||||
lazyLoadedSingletonObj = new LazyLoadedSingleton();
|
||||
}
|
||||
return lazyLoadedSingletonObj;
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.baledung.billpugh;
|
||||
|
||||
public class SynchronizedLazyLoadedSingleton {
|
||||
private static SynchronizedLazyLoadedSingleton synchronizedLazyLoadedSingleton;
|
||||
|
||||
private SynchronizedLazyLoadedSingleton() {
|
||||
}
|
||||
|
||||
public static synchronized SynchronizedLazyLoadedSingleton getInstance() {
|
||||
if (null == synchronizedLazyLoadedSingleton) {
|
||||
synchronizedLazyLoadedSingleton = new SynchronizedLazyLoadedSingleton();
|
||||
}
|
||||
return synchronizedLazyLoadedSingleton;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user