Created
July 22, 2014 12:21
-
-
Save scheffield/6510301796c68a01f2dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* LazySingleton#getInstance instatiate a singleton on the first request. | |
* | |
* Due to the loading behavior of static fields, this aproach is guaranteed to be thread safe. | |
*/ | |
public final class LazySingleton { | |
private static class InstanceHolder { | |
public static final LazySingleton INSTANCE = new LazySingleton(); | |
} | |
private LazySingleton() { | |
} | |
@Nonnull | |
public static LazySingleton getInstance() { | |
return InstanceHolder.INSTANCE; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment