金杯独酒 2016-04-26 15:07 采纳率: 0%
浏览 1361

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)

  • 写回答

3条回答 默认 最新

  • devmiao 2016-04-26 15:09
    关注
    评论

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料