PropertySingleton

From Stack Overflow
Jump to: navigation, search
package org.ninjasoft.util;

import java.util.Properties;

/**
 * This is a Singleton Properties object that will allow threads to store
 * static information that can be passed to one another.  
 */
public class PropertySingleton extends Properties
{
    private static PropertySingleton theSingleton = null;
    
    /** 
     * Private constructor--cannot be called directly.  Use 
     * getPropertySingleton instead! 
     */
    private PropertySingleton()
    {
        super();
    }
    
    /** 
     * Private constructor--cannot be called directly.  Use 
     * getPropertySingleton instead!  In actuality, this constructor is
     * NEVER used.
     */
    private PropertySingleton(Properties defaults)
    {
        super(defaults);
    }
    
    /** 
     * Use this instead of a constructor.  If one has already been constructed,
     * it is returned.  Otherwise, a new one is created before returned.
     */
    public static PropertySingleton getPropertySingleton()
    {
        if (theSingleton == null)
            theSingleton = new PropertySingleton();
        return theSingleton;
    }
}

Personal tools