你的DBManager有没有做过连接回收的清理工作?
还有,把你的连接池的java代码贴出来。

解决方案 »

  1.   

    以下是我在用的連接池代碼,一起研究研究:
    package mrp.util;
    import java.util.Stack;
    import java.sql.Connection;
    import java.sql.SQLException;
    import java.sql.DriverManager;
    import java.util.Enumeration;public final class ConnectionPool {    public Stack pool;
        private long timeout;
        private static ConnectionPool mySelf;
        private Connection con;    private  ConnectionPool() {
        }    public synchronized static ConnectionPool getInstance(){ if(mySelf == null){
        mySelf = new ConnectionPool();
    } return mySelf;
        }    public synchronized void initialize(int numCons,long timeout) throws SQLException{
    if(pool != null){
        throw new SQLException ("Pool already initialized");
    }
    try{
        this.timeout = timeout;
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        pool = new Stack();
        for(int i=0 ; i < numCons;i++){
    pool.push(DriverManager.getConnection("jdbc:odbc:MyDB","sa","123456"));
        }
    }
    catch(ClassNotFoundException ex){
        throw new SQLException("Driver not found!!!");
    }
        }
        public synchronized Connection getConnection() throws SQLException{
    if(pool == null){
        throw new SQLException ("Pool not initialized,不能連接到數據庫,請重新登錄");
    }
    /*
    while(pool.empty()){
        try{
    wait(timeout);
        }
        catch(InterruptedException ex){
    throw new SQLException ("Connection not available,目前無有效的數據庫連接,請待會再試");
        }
    }
    */
    con = (Connection) pool.pop();
    return con;
        }    public synchronized void releaseConnection(Connection con) throws SQLException {
    if(pool == null){
        throw new SQLException ("Pool not initialized,不能連接到數據庫,請重新登錄");
    }
    pool.push(con);
    notifyAll();
        }
        public synchronized int getConnectionCount() throws Exception{
    //返回當前連接池中可用的連接數
    return pool.size();
        }
        public void destroyPool() throws SQLException {
    if(pool == null){
        throw new SQLException("Pool not initialized,不能連接到數據庫,請重新登錄");
    }
    while(!pool.empty()){
        ((Connection)pool.pop()).close();
        pool = null;
    }
        }
    }