XID 的简历已提高 0:未知

发布于 2025-01-03 17:54:26 字数 1317 浏览 0 评论 0原文

我正在使用 Spring 3.0.5、Hibernate 3.6.7、Atomikos TransactionEssentials 3.7.0 和 MySQL 5.5

我最近遇到了这个问题,连接池中的连接在 8 小时后超时,并被服务器重置,导致出现消息“resume for XID ” ???'引发 0:未知

这是我的数据源配置:

<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>

当我调查时,我发现选项 autoReconnect=true 仅在延迟 2 秒后重新连接我的故障连接(我认为这是可配置的)。 浏览网页我发现建议增加MySQL服务器中的wait_timeout的解决方案,我认为这不是真正的解决方案。 应用程序应该能够处理死连接并自动重新连接,因为也可能有其他问题导致连接丢失。 (而且我不想向服务器发出任何指令,无论应用程序使用哪种类型)。

最后我找到了一个很好的解决方案,我将其作为答案发布以帮助面临相同或类似问题的人们。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

江心雾 2025-01-10 17:54:26

通过在数据源的配置上插入行:

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

,似乎在使用之前测试了连接,如果连接断开则重新连接。
我用 wait_timeout=60 进行了尝试,甚至在我的应用程序运行时重新启动了 MySQL 服务器...

结果:不再有异常和错误!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文