I am basically looking for a caching mechanism for the users of HelperWrapper. Is this a correct use of double checked singleton?
final class HelperWrapper {
private static volatile Helper helper = null;
public static Helper getHelper() {
if (helper == null) {
synchronized (HelperWrapper.class) {
if (helper == null) {
helper = new Helper();
}
}
}
return helper;
}
}
I know this wouldn't prevent someone from instantiating their own Helper objects, but that isn't the goal.
Additional info:
- I cannot modify the Helper class to make the constructor private. Nor do I want to.
- The requirements dictate that the helper should not be eagerly instantiated