/*

 * MySingleton.java

 *

 * Disclaimer:

 * ZebraSoft.com disclaims all warrantees with regard to documents/programs, including

 * all implied warranties. In no event shall ZebraSoft.com be liable for indirect or

 * consequential damages or any damages whatsoever resulting from loss of use, data or

 * profits arising out of the use of documents/programs.

 *

 * All content included on this site, such as text, graphics, logos, button icons,

 * images, audio clips, video clips, digital downloads, programs, data compilations,

 * and software, is the property of ZebraSoft.com or its content suppliers and

 * protected by United States and international copyright laws.

 *

 * This site or any portion of this site may not be reproduced, duplicated,

 * copied, sold, resold, visited, or otherwise exploited for any commercial

 * purpose without express written consent of ZebraSoft.com.

 */

 

package creational_patterns.my_singleton;

 

/**

 *

 * @author Sam Eldin

 */

import java.lang.*;

import java.util.*;

import java.io.*;

 

 

public class MySingleton {

   

    private static MySingleton instance;

   

    /** Creates a new instance of MySingleton */

    private MySingleton() {

    }

 

    /*

     *

     */

    private synchronized static void createAnInstance(){

        if(null == instance){

            instance = new MySingleton();

            System.out.println("A new MySingleton is created");

        }

    }

    /*

     *

     */

    public  static MySingleton makeInstance(){

        if(null == instance)

            createAnInstance();

        else

           System.out.println("A copy of MySingleton is already created");

        return instance;

    }

    /*

     *

     */

    protected void finalize()  {

                instance = null;

        try {

            super.finalize();

                }

                catch(Throwable MyThrowable) {

            System.out.println("finalize() catch clause");

                }

  }

}



Back to Command