使用单例模式读取Properties文件
来源:互联网 发布:好大夫软件靠谱吗 编辑:程序博客网 时间:2024/06/02 16:02
其实读取属性文件很简单,也就是几行代码的事,但是最近我做项目是发现多线程并发时会有很多问题,所以自己用单例模式写了一个多线程并发的安全读取类,与大家共享一下,以下是代码 :
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
* 读取Properties属性文件
* @author LYF
*/
public class Env extends Properties {
private static Env instance;
public static Env getInstance(String path){
if (instance != null){
return instance;
}else {
makeInstance(path);
return instance;
}
}
private static synchronized void makeInstance(String path){
if (instance == null){
instance = new Env(path);
}
}
private Env(String path){
InputStream is = getClass().getResourceAsStream(path);
try {
load(is);
} catch (IOException ex) {
System.err.println("错误信息: 读取属性文件失败!");
System.err.println("请确认 【"+ path +"】 文件是否存在。");
}
}
}
- 使用单例模式读取Properties文件
- 使用单例模式读取properties文件
- 单例模式读取Properties文件
- 读取Properties文件(单例模式)
- 单例模式读取Properties文件
- 使用单例模式加载properties文件
- 使用单例模式加载properties文件
- JAVA读取properties文件代码 单例模式
- JAVA单例模式读取properties配置文件
- 【设计模式:单例模式】使用单例模式加载properties文件
- 【设计模式:单例模式】使用单例模式加载properties文件
- 单例模式 [ Properties ]
- java 读取properties文件,运用 使用properties
- 使用Properties读取XML文件
- 使用spring读取properties文件
- Java 单例模式获取Properties文件内容
- java中的Properties类的使用 与单例模式
- Properties读取properties文件
- Software Engineering is Dead …
- Ruby on rails开发从头来(windows)(七)-创建在线购物页面
- 传智播客Hibernate视频教程学习笔记34
- 构建在SDH上的千兆以太网
- Headfirst-7 单例模式
- 使用单例模式读取Properties文件
- php webservices之soap篇
- 第四层交换机所支持的服务器负载均衡方式
- 为windows mobile (PPC)添加命令行工具
- 使用Live Writer在CSDN上发布博客
- 图片
- oracle定时任务[转]
- linux nfp设置
- 大学绝世对联