hello
I want to know what settings should have for safe updates using stateless beans (if it is possible), when have concurrency. I try to test using this code:
//this code is from Runnable objects (I have many objects of this type):
for(int i=0;i<UPDATE_NO;i++){
int amount = ran.nextInt(1000);
amountSum +=amount;
testSessionC.adjust2Balance(balance.getId(),amount);
}
@Stateless
@Remote(TestSessionC.class)
@Local(TestSessionC.class)
public class TestSessionCBean implements TestSessionC{
@PersistenceContext(unitName = "...")
EntityManager em;
public void adjust2Balance(long id, int amount) {
Balance b = em.find(Balance.class, id);
em.lock(b, LockModeType.WRITE);
float old = b.getAmount();
b.setAmount(old+amount);
em.merge(b);
}
}
@Version
@Column(name = "OPTLOCK")
public int getVersion() {
return version;
}