This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Race condition

 
Mary Cole
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic