views:

110

answers:

1

hi, i am using toplink, but i am getting some problem while updating the values. this is my code snippet

ExpressionBuilder builder = new ExpressionBuilder();
Expression expr = builder.get("addressId").equal("2");
Address address1 = (Address)uow.readObject(Address.class, expr);
address1.setPincode(address1.getPincode() + 1);
uow.registerObject(address1);
uow.writeChanges();

as my use case is that i executing the same code in multi threaded environment for say 10 threads, so after the execution i should get 10 as the value for pincode in DB if initial value was 0. but when i am executing the code i am not getting proper values. can anyone please help me

A: 

It sounds like you have a racing condition here. The operation sequence starting from read object through the write changes should be treated as atomic, which means that no thread can be allowed to read if another thread is not completed its part.

I do not see any synchronization code to achieve this. Without such code instead of 10 you will randomly recieve any number from 1 to 10

mfeingold