Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.pastebin.maroph;
- /**
- * Java Singleton sample.
- * <p>
- * This code is based on the following article:
- * <pre>
- * Title : Effective Ways to Implement and Use the Singleton Design Pattern
- * Sample : Class Holder Singleton
- * URL : https://community.oracle.com/docs/DOC-918906
- * </pre>
- * <p>
- */
- public class JavaSingleton {
- /** Private constructor */
- private JavaSingleton() {
- /* the body of the constructor here */
- }
- /**
- * Access point to the unique instance of the singleton.
- * @return return the singleton
- */
- public static JavaSingleton getInstance() {
- return JavaSingletonHolder.INSTANCE;
- }
- /**
- * Private singleton holder class.
- */
- private static class JavaSingletonHolder{
- /** create the singleton instance */
- private static final JavaSingleton INSTANCE = new JavaSingleton();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment