Can Spring transactions provide the necessary mutual exclusion if DB calls are coming from multiple machines
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.
精彩评论