XID 的简历已提高 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过在数据源的配置上插入行:
,似乎在使用之前测试了连接,如果连接断开则重新连接。
我用
wait_timeout=60
进行了尝试,甚至在我的应用程序运行时重新启动了 MySQL 服务器...结果:不再有异常和错误!
By inserting the line:
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!