atomikos + druid 连接超时失效

atomikos + druid 连接超时失效,需要多次连接才能成功。

首次连接会报异常:

2018-01-08 16:58:12 DEBUG [com.jpcar.model.dao.jpcar.AdminDao.getByName:org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:145)] ==> Parameters: root(String)
2018-01-08 16:58:12 ERROR [com.alibaba.druid.pool.DruidPooledStatement:com.alibaba.druid.pool.DruidPooledStatement.errorCheck(DruidPooledStatement.java:296)] CommunicationsException, druid version 1.1.6, jdbcUrl : jdbc:mysql://localhost:3306/jpcar?serverTimezone=PRC&useSSL=false&useUnicode=true&characterEncoding=UTF8&autoReconnect=true, testWhileIdle true, idle millis 94276, minIdle 5, poolingCount 3, timeBetweenEvictionRunsMillis 8000, lastValidIdleMillis 94276, driver com.mysql.jdbc.Driver, exceptionSorter com.alibaba.druid.pool.vendor.MySqlExceptionSorter
2018-01-08 16:58:12 ERROR [com.alibaba.druid.pool.DruidDataSource:com.alibaba.druid.pool.DruidDataSource.handleFatalError(DruidDataSource.java:1594)] discard connection
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 91,089 milliseconds ago.  The last packet sent successfully to the server was 1 milliseconds ago.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:989)
    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3556)
    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3456)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3897)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2524)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2677)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2549)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
    at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1192)
    at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3051)
    at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_execute(FilterEventAdapter.java:440)
    at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3049)

而 druid 连接池也配置了

<property name="validationQuery" value="SELECT 1" />
        <property name="timeBetweenEvictionRunsMillis" value="2800000" />
        <property name="minEvictableIdleTimeMillis" value="600000" />
        <property name="testWhileIdle" value="true" />
        <property name="testOnBorrow" value="false" />
        <property name="testOnReturn" value="false" />

 

等数据库的wait_timeout到时,依然会报错,需要多次连接才成功。

 

解决:

在配置 AtomikosDataSourceBean 时 配上 连接检查:

    <bean id="jpcarAtom" class="com.atomikos.jdbc.AtomikosDataSourceBean"
        init-method="init" destroy-method="close">
        <property name="uniqueResourceName" value="mysql/jpcar" />
        <property name="xaDataSource" ref="jpcar" />
        <property name="maintenanceInterval" value="28000" />
        <property name="testQuery" value="SELECT 1" />
    </bean>

具体解决方案

至于原理,不懂。瞎蒙到的。

估计是druid那边的连接移除了,atomikos那还有缓存。

 

转载于:https://www.cnblogs.com/qingyibusi/p/8243826.html

参与评论 您还未登录,请先 登录 后发表或查看评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:编程工作室 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值