简体   繁体   English

如何处理:通信链路故障

[英]How to handle: Communication link failure

We're using Spring 2.5.4/Hibernate 3.2/Websphere Application Server 6.1.0.17. 我们使用的是Spring 2.5.4 / Hibernate 3.2 / Websphere Application Server 6.1.0.17。 We've deployed the application on an AIX box. 我们已经在AIX机器上部署了该应用程序。 The next day when I come in, I try to log into the application. 第二天,当我进来时,我尝试登录应用程序。 I get this exception on the page: 我在页面上遇到此异常:

Error 500: Request processing failed; nested exception is org.springframework.dao.DataAccessResourceFailureException: could not execute query; nested exception is org.hibernate.exception.JDBCConnectionException: could not execute query

I checked the System.Out logs and see further details. 我检查了System.Out日志并查看更多详细信息。 (Used pastebin because the log formatting was really screwing up the page layout) (使用了pastebin,因为日志格式化确实搞砸了页面布局)


The line of our code that is causing our exception is: 导致我们异常的代码行是:

List loginList = getHibernateTemplate().find("from Login  
    where storeId =" + id + " and password ='" + password + "'");

We are wiring the connection in Spring's applicationContext.xml. 我们在Spring的applicationContext.xml中连接连接。 We are aware that the connection on the AS400 drops at times (they may restart the system overnight--I'm not sure). 我们知道AS400上的连接有时会丢失(它们可能会在一夜之间重启系统 - 我不确定)。 However, we would preferably not want to open a new connection when we are wiring everything in the applicationContext. 但是,当我们连接applicationContext中的所有内容时,我们最好不要打开新连接。

This problem occurs irregardless of using a DataSource/JNDI or JDBC 无论使用DataSource / JNDI还是JDBC,都会出现此问题

Does anybody know of any settings to add to either Spring or Hibernate to check if the connection gets stale, and if so, drop it and create a new one? 有没有人知道要添加到Spring或Hibernate的任何设置来检查连接是否过时,如果是,请删除它并创建一个新的? Or any other ideas to resolve this issue? 或者其他任何想法来解决这个问题? Let me know if you need more information/code. 如果您需要更多信息/代码,请与我们联系。

Much appreciated, 非常感激,

Chris 克里斯

Update: 更新:

Checked out some posts on the Spring Community Forums and I've implemented my DataSource with commons-dbcp which has some properties like 'testWhileIdle' and 'validationQuery'. 查看了Spring社区论坛上的一些帖子,我用commons-dbcp实现了我的DataSource,它有一些属性,比如'testWhileIdle'和'validationQuery'。 I'm going to leave the app running and check it again in the AM. 我要让应用程序继续运行并在AM中再次检查它。 Will post an update on the results. 将发布结果更新。

Update#2: 更新#2:

Using dbcp-commons BasicDataSource seems to correct this issue, which appears to be a network problem. 使用dbcp-commons BasicDataSource似乎可以解决这个问题,这似乎是一个网络问题。 Websphere has pooled connections, and if there's a network issue on the AS400 side, it will try to use the connection it has, which it doesn't know is 'stale'. Websphere已经汇集了连接,如果AS400端存在网络问题,它将尝试使用它具有的连接,它不知道是“陈旧”。 Using a validationQuery with a time interval is a cheap (but efficient) way to solve this problem--but there may be a better way on the Websphere side, under configuration. 使用带有时间间隔的validationQuery是解决此问题的一种廉价(但有效)的方法 - 但在配置下,Websphere端可能有更好的方法。 But, might as well not change what's not broken, so until this fails, it will probably be our solution going forward. 但是,不妨改变那些没有被破坏的东西,所以直到失败,这可能是我们未来的解决方案。

Ah, that's what I was gonna say... the problem must be solved in the connection pool, by validating connections before returning them. 啊,这就是我要说的......问题必须在连接池中解决,通过在返回之前验证连接。 DBCP has validationQuery, and JBoss also has something similar; DBCP有validationQuery,JBoss也有类似的东西; I'm sure Websphere must have something similar in its connection pool to validate connections before handing them out. 我确信Websphere必须在其连接池中有类似的东西才能在发送之前验证连接。 Even if you don't use testWhileIdle, if the connection is found to be invalid, a new one is created and handed to you by the pool instead of the invalid one. 即使您不使用testWhileIdle,如果发现连接无效,也会创建一个新连接并由池传递给您而不是无效的连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM