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

Tim Eck teck at terracottatech.com
Fri Feb 9 13:47:52 EST 2007


Bela Ban wrote:
> Question: in the code below, will we acquire 1000 cluster-wide locks ?
> 
> Lock lock=new ReentrantLock(); // make it distributed
> 
> for(int i=0; i < 1000; i++) {
>  lock.lock(); // acquires a distributed lock across the cluster
>  try {
>    // do something
>  }
>  finally {
>    lock.unlock();
>  }
> }

As a courtesy of to the members of concurrency-interest, a terracotta specific discussion is perhaps better suited for a 
terracotta specific mailing list or forum.

With regards to your question, the answer is that it depends. In the absence of contention for the lock from another 
node, there will only be one cluster level (ie. remote) lock acquisition necessary. If there is contention from another 
thread in the same node, then lock will behave the same as if it were not distributed at all.

-tim



More information about the Concurrency-interest mailing list