import java.io.IOException;
import java.util.Properties;
/**
* 功能:可以为别人提供一个唯一的properties对象
* 单例模式:懒汉式的写法。考虑了多线程情况下的线程安全问题。
*
*/
public class PropsHolder {
private static Properties prop;
public static Properties getProp() throws Exception{
if(prop==null){
synchronized (PropsHolder.class) {
if(prop==null){
prop = new Properties();
prop.load(PropsHolder.class.getClassLoader().getResourceAsStream("datacollect.properties"));
}
}
}
return prop;
}
}
java中单例模式的懒汉式写法
最新推荐文章于 2022-10-31 01:12:13 发布