日志打印两次(问题)

今天碰到了一个日志被打印两次的问题

Configuration类

/**
 * 配置文件信息
 * @author Administrator
 *
 */
public class Configuration {

private static Logger LOG = Logger.getLogger(Configuration.class);

/**
* 文件路径(备用 当前信息刷新到本地)
*/
public static String filePath = null;
/**
* 键值对
*/
private static Properties prop = null;
/**
* 静态构造函数
*/
static{
if(prop==null){
readConfiguration();
}
}
/**
* 默认构造函数
*
*/
public Configuration(){
if(prop==null){
readConfiguration();
}

}
/**
* prop
* @return
*/
public Properties getProperties(){
return prop;
}
/**
* 获取值
* @param key
* @return
*/
public String getValue(String key){
if(key!=null&&!key.equals("")){
return prop.getProperty(key);
}
return null;
}
/**
* 获取值
* @param key
* @return
*/
public String getValue(String key,String defaultVaule){
if(key!=null&&!key.equals("")){
return prop.getProperty(key,defaultVaule);
}
return null;
}
/**
* 读取配置信息

* @return
*/
private static synchronized void readConfiguration() {
/**
* 读取dataexchange.properties文件
*/
InputStream in = null;
Properties p = null;
try {
URL url = DEUtil.class.getResource(Constants.CONFIG_FILE_NAME);
if(url!=null){
filePath = java.net.URLDecoder.decode(url.getPath(),"utf-8");
LOG.info(filePath);
in = url.openStream();
}else{
in = DEUtil.class.getResourceAsStream(Constants.CONFIG_FILE_NAME);
}
p = new Properties();
if(p!=null){
p.load(in);
}else{
throw new NullPointerException();
}
} catch (FileNotFoundException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
try {
if(in!=null){
in.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (p != null) {
prop = p;
}else{
throw new NullPointerException();
}
}
/**
* 刷新键值对到本地文件
*
*/
public synchronized void porpertiesFlushBack(){
if(prop!=null){
//文件输出流 
OutputStream fos = null;
try {
fos = new FileOutputStream(Configuration.filePath);
//将Properties集合保存到流中
prop.store(fos, "Copyright (c) dlmu 233"); 
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
try {
if(fos!=null){
fos.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}else{
throw new NullPointerException();
}
}
}


还有一个工具类:DEUtil(贴部分代码)

/**
 * 数据交换工具类
 * 
 * @author Administrator
 * 
 */
public class DEUtil {
/**
* 配置信息
*/
private static Configuration conf = new Configuration();

。。。。。省略部分代码

}

还有一个入口:DataExchangeClient

/**
 * 数据交换客户端
 * @author Administrator
 *
 */
public class Client {

private static Logger LOG = Logger.getLogger(Client .class);
/**
* 配置信息
*/
private Configuration conf = null;
/**
* @param args
* @author Administrator
*/
public static void main(String[] args){
/** 创建客户端实例 */
Client client = new Client ();
client.run();
}
/**
* 初始化函数

*/
private void initial(){
this.conf = new Configuration();

}
/**
* 默认构造函数
*
*/
public Client () {
initial();
}

}


整个执行下来会出现打印两次日志 就是红色的地方执行了两次


整个过程都是单线程


暂时还不知道怎么解释(望有人能指点下 谢谢)



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值