[concurrency-interest] Synchronization/locking in a clustered JEE environment

Ryan LeCompte Ryan.LeCompte at pango.com
Fri Feb 9 11:07:21 EST 2007

In simple Java applications that reside in a single JVM, it is safe to do things like the following when there are multiple threads of execution:
public synchronized void go() { ...}
synchronized (LOCK) {
However, consider the case where there are multiple instances of stateless session beans in a clustered JEE environment. You may have different instances of the same stateless session bean running in multiple JVMs. How would one ensure that a "global lock" is acquired if I have a method on the stateless session bean that looks like the following:
public void doSomething() {
   // Perform some logic that does not need to be globally protected....
   synchronized (LOCK) {
      // Perform some logic that DOES need to be globally protected....
  // Perform other logic that does not need to be globally protected....
I know that I could use container-managed transactions to provide locking semantics at the method level, but what is the suggested approach to get finder-grained distributed locking as demonstrated in the above example? I'd love to be able to continue using the new 1.5 concurrency utilities for read/write locks, etc. Is there some general pattern that I'm not aware of?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20070209/4f244b98/attachment-0001.html 

More information about the Concurrency-interest mailing list