且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JPA事务的超时实现和会话无效

更新时间:2023-12-04 19:21:52

由于您已经在使用Spring,就这么简单:

Since you are already using Spring, it's as simple as that:

@Transactional(timeout = 300)

事务注释允许您提供超时值(以秒为单位),事务管理器会将其转发到JTA事务管理器或数据源连接池.它可以与Bitronix Transaction Manager配合使用,后者会自动将其提取.

The Transaction annotation allow you to supply a timeout value(in seconds) and the transaction manager will forward it to the JTA transaction manager or your Data Source connection pool. It works nice with Bitronix Transaction Manager, which automatically picks it up.

您还需要确保java.sql.Conenction始终处于关闭状态,并且Transaction始终会被提交(当所有操作成功时)或在失败时回滚.

You also need to make sure the java.sql.Conenction are always being closed and Transaction are always committed (when all operations succeeded) or rollbacked on failure.

使用户http会话无效与jdbc连接无关.您的jdbc连接应始终被提交/回滚并关闭(在连接池的情况下,将释放到池的连接).

Invalidating the user http session has nothing to do with jdbc connections. Your jdbc connection should always be committed/rollbacked and closed(which in case on connection pooling, will release the connection to the pool).

并确保最大池大小不大于tour db max并发连接设置.

And make sure the max pool size is not greater than tour db max concurrent connections setting.