Java 如何处理陈旧的连接?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/486964/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to handle stale connections?
提问by
Ours is a J2EE app, using Struts-EJB-Hibernate on Websphere 6.1 over Mainframe/DB2 backend, that was recently moved to production.
我们的应用程序是一个 J2EE 应用程序,在 Websphere 6.1 上使用 Struts-EJB-Hibernate,而不是大型机/DB2 后端,该应用程序最近已投入生产。
We are getting stale connection exceptionwhen the user login to the application first time or some times this exception occurs intermittently.
当用户第一次登录应用程序时,我们会收到过时的连接异常,或者有时会间歇性地发生此异常。
on the second try the user able to log in to the application. The exact error message i am getting is
在第二次尝试用户能够登录到应用程序。我得到的确切错误信息是
empcom.ibm.websphere.ce.cm.StaleConnectionException:
Execution failed due to a distribution protocol error that caused deallocation of the conversation.
The command requested could not be completed because of a permanent error condition detected at the target system.
DB2ConnectionCorrelator: AC100B80.A260.090107181206
I enabled PRETEST
option in webshere settingsand gave the interval as 60 sec, but still i am getting this issue..
我PRETEST
在 webshere 设置中启用了选项并将间隔设置为 60 秒,但我仍然遇到这个问题..
kindly share your views and help me
请分享您的观点并帮助我
i can give you more details if you need.
如果你需要,我可以给你更多的细节。
回答by
i got the answer for this
我得到了答案
using pretest old connection and new connection we can solve this issue.. the pretest query should be a basic query (select sysdate from ..)which runs anytime..
使用预测试旧连接和新连接,我们可以解决这个问题.. 预测试查询应该是一个基本查询(从 .. 中选择 sysdate),它可以随时运行..
and time interval should be maximum hence the application server will not get overhead
并且时间间隔应该是最大的,因此应用程序服务器不会得到开销
回答by alexdown
We had the same issue at first login in the morning on one of our production systems. Solution was to set the minimum size for the connection pool to zero.
早上第一次登录我们的一个生产系统时,我们遇到了同样的问题。解决方案是将连接池的最小大小设置为零。
With minimum size set to a value greater than zero (e.g., one), timed out connections are removed from the pool when they are detected as not valid, but some of them (in the example above, the last one) remains in the pool (if the minimum size is one, one connection stays in the pool, even if it is not yet a valid connection).
将最小大小设置为大于零的值(例如,一),超时连接在检测到无效时从池中删除,但其中一些(在上面的示例中,最后一个)保留在池中(如果最小大小为 1,则连接池中会保留一个连接,即使它还不是有效连接)。
Next time an application request a connection, the not valid one is served, resulting in the exception.
下次应用程序请求连接时,将提供无效的连接,从而导致异常。
Setting minimum size to zero, all non valid connections are removed from the pool, so there is no chance the connection served to the application is not yet valid (because, if it is valid, it stays in the pool, if it is not, is removed from the pool).
将最小大小设置为零,所有无效连接都将从池中删除,因此提供给应用程序的连接不可能是无效的(因为,如果有效,它将留在池中,如果不是,从池中删除)。
Using the pretest could be a valid alternative, but will take an extra effort, because every time the connection is being served to the application, is tested.
使用预测试可能是一个有效的替代方案,但需要额外的努力,因为每次为应用程序提供连接时,都会进行测试。