`
yunchow
  • 浏览: 319802 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

单例实现解析配置文件辅助类

    博客分类:
  • DBI
阅读更多
package com.yunchow.util;

/**
 * read the jdbc connection information
 * @author yunchow
 * @version 1.2  09/8/17
 */
final class ConfigBean extends java.util.Properties {
	
	private static final long serialVersionUID = 1L;
	private static ConfigBean instance;
	private static final byte[] lock = new byte[0];
	private static String fileName;
	
	private ConfigBean() {
		try {
			load(ConfigBean.class.getClassLoader().getResourceAsStream(fileName));
		} catch(Exception ex) {
			throw new ExceptionInInitializerError(ex);
		}
	}
	/** 设置配置文件的名字 */
	public static void setConfigFile(String file) {
		fileName = file;
	}
	/** 根据传过来的文件名, 得到一个配置文件的实例 */
	public static ConfigBean getInstance(String file) {
		fileName = file;
		return getInstance();
	}
	/** 得到一个配置文件的实例 */
	public static ConfigBean getInstance() {
		if(instance == null) {
			synchronized(lock) {
				if(instance == null) {
					instance = new ConfigBean();
				}
			}
		}
		// System.out.println("Jdbc config bean ->" + instance);
		return instance;
	}
	
	
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics