当前位置: 代码迷 >> Java Web开发 >> 有关问题求助!各位大哥帮忙
  详细解决方案

有关问题求助!各位大哥帮忙

热度:104   发布时间:2016-04-17 15:31:52.0
问题求助!!各位大哥帮忙!
我参考了一些资料,写了个简单的数据库连接池,其中释放数据库连接的代码是:
public   synchronized   void   freeConnection(Connection   con)   {
//   将指定连接加入到向量末尾
if(freeConnections.size() <this.maxfreeConn){//向空闲池里添加连接
        freeConnections.addElement(con);
        checkedIn--;
        notifyAll();
        System.out.print( "添加了一个空闲连接: "+freeConnections.size()+ "_ "+this.maxfreeConn);
}
else{
try{
con.close();
System.out.print( "关闭了一连接! ");
}catch(SQLException   e){
// log( "无法关闭连接!! "+con.toString());
        }
    }
}
我用freeConnections.size()得到每次调用的值都是1,应该是每调用一次加1的,直到freeConnections.size() <this.maxfreeConn;
我这里那里不妥?
freeConnections定义如下:
static   private   Vector   freeConnections   =   new   Vector();

------解决方案--------------------
static private 好好去理解一下这2个
  相关解决方案