开发者

Can Spring transactions provide the necessary mutual exclusion if DB calls are coming from multiple machines

开发者 https://www.devze.com 2022-12-17 08:03 出处:网络
I\'m porting a class from plain JDBC to use Spring.Part of this class consists of a block that find the most recent row, updates a field, and selects it into an object to be processed later.This block

I'm porting a class from plain JDBC to use Spring. Part of this class consists of a block that find the most recent row, updates a field, and selects it into an object to be processed later. This block should only be executed by one thread on one machine at a time to make sure no two threads process the same row. We've been handling mutual exclusion by locking the table, but开发者_如何学运维 as part of the move to Spring would like to use the transaction management provided.

Is the DataSourceTransactionManager powerful enough to provide mutual exclusion in the case where our code is accessing the database from multiple machines?


DataSourceTransactionManager makes use of the setAutoCommit method on java.sql.Connection. That in turn controls the transactional behaviour on the database server. The transaction itself resides in the database.

So yes, what you want to do shouldn't be a problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号