File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Race condition " Watch "Race condition " New topic

Race condition

Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362

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
author & internet detective

Joined: May 26, 2003
Posts: 33102

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.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: Race condition
It's not a secret anymore!