The Artima Developer Community
Sponsored Link

Java Buzz Forum
Distributed Locks for Java

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Talip Ozturk

Posts: 103
Nickname: talip
Registered: May, 2003

Talip Ozturk is founder of Hazelcast, distributed queue, set, map and lock implementation.
Distributed Locks for Java Posted: Jul 1, 2008 8:33 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Talip Ozturk.
Original Post: Distributed Locks for Java
Feed Title: Shared Memory
Feed URL: http://www.jroller.com/talipozturk/feed/entries/rss
Feed Description: about java, jcache, jini, javaspaces, distributed data structures and a little bit of me and life.
Latest Java Buzz Posts
Latest Java Buzz Posts by Talip Ozturk
Latest Posts From Shared Memory

Advertisement

While Hazelcast is cooking to be 1.0, distributed implementation of java.util.concurrent.locks.Lock is being developed to catch the 1.1 release in July. Hazelcast-1.0 will hopefully be generally available in June. Here is  sample code for cluster-wide object locking.


java.util.concurrent.locks.Lock myLock = Hazelcast.getLock (new MyObject());
myLock.lock ();
try {
    // do some stuff here..
} finally {
    myLock.unlock();
}

Since this is cluster-wide lock, object identity of your mutex within JVM cannot be used. Hazelcast uses binary representation of your mutex as identifier. So if binary representations of your objects are the same then Lock objects you will get for these objects will  be same cluster-wide.

Everything else works just like the way Lock javadoc says. Even lock.tryLock() with timeouts is supported.


 java.util.concurrent.locks.Lock myLock = Hazelcast.getLock (obj);
if (myLock.tryLock (5000, TimeUnit.MILLISECONDS)) {
  try {
      // do some stuff here..
  } finally {
      myLock.unlock();
  }
}


Implementation is also re-entrant; it behaves just like java.util.concurrent.lock.ReentrantLock. More importantly, you won't lose your locks after crashes. So If a member holds a lock and some of the members go down, cluster will keep your locks safe and available. Moreover, when a member leaves the cluster, all the locks acquired by this dead member will be removed so that these locks can be available for live members immediately. Currently implementation is in alpha but if you want to try it out, just drop me an email (oztalip at gmail dot com).



Read: Distributed Locks for Java

Topic: Conservation of attractive profits Previous Topic   Next Topic Topic: Plugin pros and cons

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use