resume for XID raised 0: unknown

淺唱寂寞╮ 提交于 2019-12-08 04:57:45

问题


I am using Spring 3.0.5, Hibernate 3.6.7, Atomikos TransactionEssentials 3.7.0 and MySQL 5.5

I recently faced the problem, that connections in my connectionpool timedout after 8 hours and were reset by the server causing a message "resume for XID '???' raised 0: unknown

Here is my datasource configuration:

<bean id="myDataSource"
      class="com.atomikos.jdbc.AtomikosDataSourceBean"
      init-method="init"
      destroy-method="close"
      depends-on="myConfigurer">
    <property name="uniqueResourceName" value="myPUDataSource" />
    <property name="xaDataSourceClassName" value="$CONF{database.XAdriver}" />
    <property name="poolSize" value="10" />
    <property name="xaProperties">
        <props>
            <prop key="user">$CONF{database.user}</prop>
            <prop key="password">$CONF{database.password}</prop>
            <prop key="URL">$CONF{database.url}</prop>
            <prop key="pinGlobalTxToPhysicalConnection">true</prop>
            <prop key="autoReconnect">true</prop>
        </props>
    </property>
</bean>

As I was investigating I found out that the option autoReconnect=true only reconnects my faulted connection after a delay of 2 seconds (which is configurabe I think). Browsing the web I found solutions suggesting to increase wait_timeout in the MySQL-Server, which I think is not a real solution. The application should be able to handle dead connections and reconnect automatically, because there may be other issues causing a connection loss, too. (And I don't want to make any directives to Servers whatever kind the application uses).

At last I found a good solution for this, which I will post as answer to help people facing the same or similar problems.


回答1:


By inserting the line:

<property name="testQuery" value="SELECT 1"/>

on the data source's configuration, it seems the connection is tested before use and reconnected if it's dead. I tried it with wait_timeout=60 and even with a restart of the MySQL-Server while my application was running...

Result: no more Exceptions and Errors!



来源:https://stackoverflow.com/questions/9208053/resume-for-xid-raised-0-unknown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!