Select For Update Spring Jdbctemplate
How to perform CRUD operations using JDBC with Spring framework.
Spring Jdbctemplate Api
Hi all, I am having trouble preventing a race condition in a app that accesses an Oracle database. The sequence of events goes like this: 1) My receives a request. 2) The servlet checks the value of a flag stored in the database. 3) If the flag is set to 'N' then it sets it to 'Y', and performs some other actions that must only be done once. The problem occurs when I have multiple simultaneous requests (which is common for this particular service). For example: 1 checks the flag and sees that it is N.
Db2 Select For Update
Thread 2 checks the flag and sees that it is N. Thread 1 updates the flag to Y and does the stuff that should only be done once. Thread 2 also updates the flag to Y and proceeds to duplicate the work that should only be done once. What I want is to prevent Thread 2 from reading the flag until after Thread 1 has had a chance to update it.
What is the best way to do this in? I thought about using transactions, but I wasn't sure if that would provide the intended functionality. Any and all help is greatly appreciated. Oracle apps uses object version number on many tables. Also I have seen it on some ORM software.
Select For Update No Wait
Each update on a row increases OVN by one -either with trigger or programmatically. So once you get the row for update you have an OVN then when you are updating you also provide OVN+1 and expect that to be equal to OVN+1 on the row. If not then the row data has been changed by some one since your last fetch.
Since this kind of solution can be implemented most easily by triggers, triggers also bring a burden on execution time but I guess the least among others. But also increases vendor dependencies. Just a thought to be considered. Regards, Fatih.