maroph icon

Java Singleton Sample

maroph | PRO | 09/30/15 08:21:17 AM UTC | 0 ⭐ | 337 👁️ | Never ⏰ | []
Java 5 |

0 B

|

None

|

0 👍

/

0 👎

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();
    }
}

Comments