1 Reply Latest reply on Apr 22, 2015 3:42 AM by Radim Vansa

    Infinispan lock API

    Prasad Ramachandran Newbie

      1.  Can we use infinispan lock API outside transaction?

      2.  Can we unlock a key which has been locked as

           tm.begin();

           cache.getAdvancedCache.lock(key);

           tm.commit();

       

           The key is unlocked at the time of commit. Is there any mechanism to unlock without using commit ?

       

      3.  cache.getAdvancedCache.getLockManager()  ?

           What is the use case of this LockManager ?

        • 1. Re: Infinispan lock API
          Radim Vansa Master

          1. No, you would get UnsupportedOperationException("Calling lock() on non-transactional caches is not allowed"). You can't even use locking with optimistic transactions, here you'd get

          InvalidCacheUsageException("Explicit locking is not allowed with optimistic caches!")

           

          2. This is not possible - the key is actually written to the cache during the commit, when you call put(), it's only recorded in transaction and locked (with pessimistic transactions). Therefore, you cannot unlock it prematurely.

           

          3. This exposes internal state of locks; it seems that it's used mostly from tests to assert if some keys are locked, and to retrieve statistics... It gives you info only about node-local locks, so I wouldn't recommend you to try to use it unless you exactly know what you want to do.