zoukankan      html  css  js  c++  java
  • 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那还有缓存。

  • 相关阅读:
    设计模式之开篇(C#语法) 爱拼才会赢
    C#语法糖之第一篇:自动属性&隐式类型 爱拼才会赢
    C#语法糖之第四篇: 扩展方法 爱拼才会赢
    C#中this在扩展方法的应用
    笔记20120215_转义字符_运算符
    Linux基本操作
    SQL创表
    软件测试的概念
    java 线程池
    Redis广播
  • 原文地址:https://www.cnblogs.com/qingyibusi/p/8243826.html
Copyright © 2011-2022 走看看