我有一个应用程序在 Websphere Application Server 6.0 (WAS) 内的 Websphere Portal Server 中运行。在此应用程序中,对于一个需要很长时间才能完成的特定功能,我将触发一个执行此操作的新线程。这个新线程从 Hibernate 打开一个新 session 并开始用它执行数据库事务。有时(无法看到模式),线程内的事务工作正常并且过程成功完成。但有时我会收到以下错误:
org.hibernate.exception.GenericJDBCException: could not load an entity: [OBJECT NAME#218294]
...
Caused by: com.ibm.websphere.ce.cm.ObjectClosedException: DSRA9110E: Connection is closed.
Method cleanup failed while trying to execute method cleanup on ManagedConnection WSRdbManagedConnectionImpl@642aa0d8 from resource jdbc/MyJDBCDataSource. Caught exception: com.ibm.ws.exception.WsException: DSRA0080E: An exception was received by the Data Store Adapter. See original exception message: Cannot call 'cleanup' on a ManagedConnection while it is still in a transaction..
我怎样才能阻止这种情况发生?为什么 WAS 似乎想要终止我的连接,尽管它们还没有完成。有没有办法阻止 WAS 尝试关闭此特定连接?
谢谢
最佳答案
我在我的 other answer 中提到了两个可能的原因: 1. hibernate.connection.release_mode 可选参数或 2. unmanaged threads 的问题。现在我读到了这个问题,我真的开始认为您的问题可能与您生成自己的线程这一事实有关。由于它们不受容器管理,因此这些步骤中使用的连接可能会显示为“泄漏”(未正确关闭),如果 WAS 尝试在某个时刻恢复它们,我不会感到惊讶。
如果你想启动一个长时间运行的作业,你应该使用 WorkManager。不要自己生成线程。
关于java - 后台线程的 JDBC 连接在 Websphere 中关闭访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2647912/