-
1. Re: Query related to jboss cache transaction
manik Jan 15, 2008 7:58 AM (in response to arif.mohammed1)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 Jan 15, 2008 8:56 AM (in response to 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 Jan 22, 2008 3:50 PM (in response to arif.mohammed1)Even with 2-phase synchronous commits, there is a chance that one transaction won't succeed, in which case you could retry the transaction.