I have to update status of a variable in database before processing it for ensuring only one thread process it.
For this I am using spring's transactionTemplate
so my doubt is:
If I have something like:
TransactionTemplate(new TransactionCallback()){
execute(){
try{
query 1 - having select for update
query 2 - having update
} catch(Exception e){
TransactionStatus.setRollBackOnly();
throw e;
}
}
}
I use spring's jdbctemplate
with autocommit on
.
How many commits happen? Does commit happen for every query? Is this good way to achieve synchronization?