3 Replies Latest reply on Jan 22, 2008 3:50 PM by manik

    Query related to jboss cache transaction

    arif.mohammed1

      Hi,

      I have configured jboss cache programatically though a servlet on glass fish in clustered environment and cluster name in cache configuration file is "JBossCache-Cluster"

      Now My requirement is whenever an instance is trying to change the values of POJO's in this cache other instance should not able to read or write in this cache(exclusive lock on entire cache)

      My understanding is whenever i start a transaction, it will acquire an exclusive lock on entire cache, is this correct?

        • 1. Re: Query related to jboss cache transaction
          manik

          No. A transaction will just scope locks on your local cache instance for the duration of the transaction. During the 2-phase commit (for sync replication) remote locks are acquired. If these cannot be acquired, the transaction fails and rolls back.

          • 2. Re: Query related to jboss cache transaction
            arif.mohammed1

            Hi manik,

            Iam newbie to jboss cache, Please clarify me regarding my understanding.

            I am using the POJO cache in clustered environment as follows.

            public class POJO{
            private int count;
            private setCount(int count){
            this.count = count;
            }
            private int getCount(){
            return count;
            }
            }

            A POJO object will be created and attached to the cache through a servlet in instance1 as follows

            POJO obj = new POJO();
            cache = PojoCacheFactory.createCache("replSync-service.xml", true);
            cache.attach("monitor", obj); // I hope "/monitor" will be the FQN under which obj will be stored

            Now 2 transactions t1,t2 will be trying to increment the value of count from instance2,instance3 respectively as follows

            cache = PojoCacheFactory.createCache("replSync-service.xml", true);
            POJO obj = (POJO) cache.find("monitor");
            tx.begin();
            int currentValue = obj.getCount();
            currentValue++;
            obj.setCount(currentValue);
            tx.commit();

            Now how can i guarantee that the count value is not over written by t2 which was written by t3

            Can i acquire explicit lock on "/monitor" before starting a transaction so that no other transaction in other instance should be able to read/write on "/monitor" ?

            Iam expecting that if isolation level "SERIALIZABLE" is used i don't need to bother about the above problem and repeat the statements in between begin,commit untill it succeeds. Am i right ?

            • 3. Re: Query related to jboss cache transaction
              manik

              Even with 2-phase synchronous commits, there is a chance that one transaction won't succeed, in which case you could retry the transaction.