What are the best ways to avoid race conditions in jsp at the same time not to slow down the process.I have tried
isThreadSafe=false
synchronized(session)
however is there any other alternate solution is available?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A one-size-fits-all solution (e.g.
threadSafe=false) causes requests to be executed one at a time. And that inevitably slows down request processing.To that avoid that scenario, you need to understand why you are getting race conditions and (re-)design your architecture to avoid the problem. For example:
if the race condition is in updates to some shared in-memory data structures, you need to synchronize access and updates to the data structure at the appropriate level of granularity
if the race condition is in updates to the your database, you need to restructure your SQL to use transactions at the appropriate level of granularity.
These are just (possible) schemas for how to solve your race condition problems. In reality, you have to understand the root causes yourself.