• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Syncronized methods and Load Balance

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have two questions.

1. If I'm in a load balancing scenario (Apache Server + 3 Tomcats: Tomcat1, Tomcat2 and Tomcat3) and I have a synchronized method. How will the application execute this method for 2 simultaneous access? It will be transparent, even if the first request of the synchroned method is alocated to the Tomcat1 and the second request of the synchroned method is alocated to the Tomcat2, Will the synchronized execution be maintained?

2. When an user calls a synchronized method and it broken (ex.: a loop), and, the second user is trying to call the same synchronized method. What will happen in that case? Will the second user wait infinitely? If Yes, can I configure a timeout?

Thanks in advance!
 
Saloon Keeper
Posts: 22484
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java synchronized code feature is only local to the JVM that the method is executed in. Other JVMs can be executing the same code, but they will be unaware of each other and therefore won't synchronize with each other. That doesn't normally matter, since the language-based synchronized feature is mostly about maintaining the integrity of data internal to the JVM.

When clustering, you may have other synchronization needs where you need inter-JVM synchronization. The mechanisms you use in this case depend on what you're trying to keep synchronized. One of the more common things is databases, and for that you normally use transactions and/or table or row locking. For general work requests, you might use a message queue system.
 
Heroic work plunger man. Please allow me to introduce you to this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic