Forums Register Login
Race condition

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
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.
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards

This thread has been viewed 687 times.

All times above are in ranch (not your local) time.
The current ranch time is
Jan 20, 2018 12:02:54.