在Websphere中关闭后台线程的JDBC连接

Jai*_*cia 2 java websphere hibernate jdbc

我在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..
Run Code Online (Sandbox Code Playgroud)

我怎么能阻止这种情况发生?为什么看起来WAS想要杀死我的连接,即使他们没有完成.有没有办法阻止WAS尝试关闭这个特定的连接?

谢谢

Pas*_*ent 5

我在另一个答案中提到了两个可能的原因:1. hibernate.connection.release_mode可选参数或2. 非托管线程的问题.现在我读了这个问题,我真的开始认为你的问题可能与你正在产生自己的线程有关.由于它们不是由容器管理的,因此这些踏板中使用的连接可能显示为"泄漏"(未正确关闭),如果WAS尝试在某些时候恢复它们,我不会感到惊讶.

如果要启动长时间运行的作业,则应使用WorkManager.不要自己生成线程.