if(
this.con==null||this.con.isClosed()){
            return this.con = DBUtil.getConnection();
}
这个判断实现判断con是否为空然后在判断isClosed,如果为空,就直接返回。不会载执行isClosed的判断。这就是短路。
这就相当于
if(this.con==null){
            return this.con = DBUtil.getConnection();
}
if(this.con.isClosed()){
      return this.con = DBUtil.getConnection();
}
并且上面的代码也不会发生NullPointerException 的异常。因为如果为空,就直接取得新的连接。
|----------------------------------------------------------------------------------------|
                           版权声明  版权所有 @zhyiwww
            引用请注明来源 http://www.blogjava.net/zhyiwww    
|----------------------------------------------------------------------------------------|
	
posted on 2010-02-09 11:45 
zhyiwww 阅读(712) 
评论(0)  编辑  收藏  所属分类: 
j2ee