Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Multiple Instance of App server- threading issue

Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The application architecture - We have 2 application server(NOn clustered environment) with the same application , both the application server pointing to the single database.

Service : we have service which reads the database and check for the entity and if that entity is not present its adds it to the database and if it is present it will update the entity.

Problem : we have multiple threads running simultaneously to through the 2 application server. Both at the same time reads the Database and find that the entity is not present. Both thread adds the same entity in the Database. and we have duplicate rows.

The primary key and entity are different so the database doesn't restrict the duplicate rows.

Ques :
By making code thread safe by using synchronized, will it prevent the above problem ? I doubt that as we have 2 application server running on different JVM. How to prevent the above problem ? thanks in advance
Farmers know to never drive a tractor near a honey locust tree. But a tiny ad is okay:
Garden Master Course kickstarter
    Bookmark Topic Watch Topic
  • New Topic