I am exploring Locks and need some help understanding it.

1. To take a distributed lock on a key, does key need to exists in cache?

2. Once distributed lock is taken on existing cache key, does any operation
on that cache key entry restricted from other thread? other thread is not
explicitly taking lock. Example -

Thread 1 -
Lock lock = cache.Lock("key1");
try {
lock.lock();
//do something 
} finally { lock.unlock(); }

Thread 2 -
cache.get("key1");
or
cache.put("key1", object);
or 
any other basic cache operation 

3. What happens if same thread tries to take lock multiple times before
unlocking it -
Lock lock = cache.lock("keyLock");
Lock lock2 = cache.lock("keyLock");
Lock lock3 = cache.lock("keyLock");


4. I had created a simple example and it failed with "Failed to unlock keys
(did current thread acquire lock with this lock instance?)". However it is
same thread tries to unlock it. I could able to resolve this by using same
Lock object instance for lock() and unlock() method. So question is - does
same thread or same Lock object instance is enforced here? 

5. Is there a way I can achieve all 4 cases listed in attached test program?
IgniteLock is what I am thinking. CacheLockExample2.java
<http://apache-ignite-users.70518.x6.nabble.com/file/n7489/CacheLockExample2.java>
  





--
View this message in context: 
http://apache-ignite-users.70518.x6.nabble.com/understanding-Locks-usage-tp7489.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Reply via email to