This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Spring and the fly likes Race condition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Race condition " Watch "Race condition " New topic
Author

Race condition

Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362
Hi,

I have a multithreaded spring stand alone app running on 2 boxes. I have a service method which checks for a record in DB and if its not there, it tries to insert in the DB. I want to handle a situation where if one thread on box A is querying to find a record, another thread on Box B should not have queried and tried to inserted the record if it didn't existed. I have constraints in DB which would throw an exception, but is there a way in Spring to prevent this race condition

Thanks in advance
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30136
    
150

If your standalone apps were pointing at a server, that could block the attempt. Since the only thing shared is a database, the database is the proper place for this check. While I imagine it is possible for the apps to communicate with each other, it seems complicated, a security issue and brittle.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Race condition
 
Similar Threads
3rd level of locking
getting Primary key when inserting
NX: Synchronize read / find?
Optimistic vs. Pessimistic Locking
Struts Action and Business layer - Thread safe?