dbcp mysql 8小时_c3p0关于mysql8小时的问题

jar包:c3p0-0.9.5-pre6.jar     mchange-commons-java-0.2.6.3.jar

背景:以前在使用ORM框架的情况下,使用连接池没出现过空闲连接超时的问题,现在新建个项目没什么框架,使用c3p0,代码如下:

private static ComboPooledDataSource ds = null;

static {

try {

ds = new ComboPooledDataSource();

ds.setDriverClass(Constant.DRIVER_CLASS_NAME);

ds.setJdbcUrl(Constant.URL);

ds.setUser(Constant.USERNAME);

ds.setPassword(Constant.PASSWORD);

ds.setMaxPoolSize(40);

ds.setMinPoolSize(5);

ds.setAutomaticTestTable("C3P0TestTable");

ds.setIdleConnectionTestPeriod(1800);

ds.setTestConnectionOnCheckin(true);

ds.setTestConnectionOnCheckout(true);

ds.setMaxIdleTime(25000);

} catch (PropertyVetoException e) {

gLog.error("ComboPooledDataSource", e);

}

}

public static synchronized Connection getConn() {

Connection con = null;

try {

con = ds.getConnection();

} catch (SQLException e1) {

gLog.error("getConn", e1);

}

return con;

}

有个线程用 getConn()获取连接后,长时间不进行数据库操作,隔天触发数据库操作时会报异常

com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:

** BEGIN NESTED EXCEPTION **

java.net.SocketException

MESSAGE: Software caused connection abort: socket write error

STACKTRACE:

java.net.SocketException: Software caused connection abort: socket write error

at java.net.SocketOutputStream.socketWrite0(Native Method)

at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)

at java.net.SocketOutputStream.write(SocketOutputStream.java:136)

at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)

at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)

at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2637)

at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1554)

at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)

at com.mysql.jdbc.Connection.execSQL(Connection.java:3176)

at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1153)

at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1266)

at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:144)

** END NESTED EXCEPTION **

Last packet sent to the server was 0 ms ago.

at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2652)

at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1554)

at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)

at com.mysql.jdbc.Connection.execSQL(Connection.java:3176)

at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1153)

at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1266)

at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:144)

有个线程一直有进行数据库操作,则正常,因此判断是MYSQL8小时问题。但是代码里几个重要属性已经配置了,是否哪里还漏了,错了。

求教!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值