2 qq 32738723 qq_32738723 于 2016.04.26 23:07 提问

javaDao c3p0 mysql 服务器挂掉!

只有个页面,连接数据库的就是一个getSession(), 一个调用Dao实现类的方法;

Dao实现类如下:

public class DptDaoImp implements DptDao {

    public List<Dpt> show_Dpt() {
        String sql ="SELECT * FROM dpt";
        Connection conn=null;
        List<Dpt> dpt_List=null;
        ComboPooledDataSource dataSource =new ComboPooledDataSource();
        try {
             conn = dataSource.getConnection();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        QueryRunner runner =new QueryRunner();
         try {
            dpt_List = runner.query(conn, sql, new BeanListHandler<Dpt>(Dpt.class));
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {
            conn.close();     //此处已经释放连接
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return dpt_List;
    }

}

c3p0的配置:

<c3p0-config>
  <default-config>
   <property name="jdbcUrl">jdbc:mysql://localhost:3306/rsp</property>
   <property name="driverClass">com.mysql.jdbc.Driver</property>
   <property name="user">root</property>
   <property name="password">root</property>
   <property name="initialPoolSize">10</property>

   <!--连接池中保留的最小连接数。-->  
   <property name="minPoolSize">10</property>

   <!--连接池中保留的最大连接数。Default: 15 -->  
   <property name="maxPoolSize">100</property>

    <!--最大空闲时间,10秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->  
   <property name="maxIdleTime">5</property>


   <property name="maxStatements">0</property> 
   <property name="maxStatementsPerConnection">0</property>


在mysql中my.ini 中最大连接 max_connections (已改为1000)

现状: 登录账号后,交替点那两个模块,60次左右就挂了,机器卡死,大大们求救啊!

出现下列提示:

警告: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@36e15d3f -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: 
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection,  **message from server: "Too many connections"**
    at sun.reflect.GeneratedConstructorAccessor18.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
    at com.mysql.jdbc.Util.getInstance(Util.java:384)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:984)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1105)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2186)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:787)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49)
    at sun.reflect.GeneratedConstructorAccessor14.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:357)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
    at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
    at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
    at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
    at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
    at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

4个回答

devmiao
devmiao   Ds   Rxr 2016.04.26 23:09
qq_32738723
qq_32738723 谢谢!
一年多之前 回复
CSDNXIAOD
CSDNXIAOD   2016.04.26 23:12

c3p0+mysql的奇怪问题
C3P0
----------------------biu~biu~biu~~~在下问答机器人小D,这是我依靠自己的聪明才智给出的答案,如果不正确,你来咬我啊!

qq_32738723
qq_32738723 感谢 !!程序运行是没有问题的。 是在点了60次左右之后出了报出异常:*message from server: "Too many connections"** connections在每次方法的结束时都已经close()掉了啊? 是肿么回事呀,感觉不能再爱了~~~~~~
一年多之前 回复
qq_32738723
qq_32738723   2016.04.26 23:22

程序运行是没有问题的。

是在点了60次左右之后出了报出异常:*message from server: "Too many connections"**

connections在每次方法的结束时都已经close()掉了啊?

是肿么回事呀,感觉不能再爱了~~~~~~

lsx991947534
lsx991947534   2016.04.27 09:38

可以查查看,到60次时有多少连接数,看看是否释放掉

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!