I have the below flow in a multi-threaded environment
- start transaction
- read n number of top rows (based on a column) from db
- check some criteria
- update those set of rows
- commit/rollback the transaction
I am using optimistic locking to handle multi-threaded scenario, but in above situation DB is always returning the same set of rows so if a second thread runs at the same time it will always fail.
Is there a better way to handle this? Could we force DB to return different set of rows for each transaction using some option?