my dog learned polymorphism*
The moose likes Web Services and the fly likes Concurrency in Web Services Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Concurrency in Web Services" Watch "Concurrency in Web Services" New topic
Author

Concurrency in Web Services

Vivek Punekar
Greenhorn

Joined: Aug 25, 2009
Posts: 12
Hello,
We are using optimistic locking using version column (JBoss + Hibernate).
Now we are planning to implement Web Services interface. My basic query is: How can we maintain data integrity?
E.g. step 1: user 1 fetches a record by sending a web service request.
step 2: user 2 in mean time modifies this record from UI.
step 3: Then user 1 modifies the record and sends it over web services to persist it.
If both these were carried from UI, user 1 would have got optimistic lock exception flow in step 3

How will the flow using web services behave? In step 3, Will user1 overwrite the changes of user 2?

Any help would be appreciated.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
A web service is for two or more applications to communicate. It is a transport mechanism.

Transaction management activities and ensuring data integrity occur at a lower layer. Whether you are using a web service or not should not matter in terms of your particular transaction management design.

Transaction management should not be occuring in the UI regardless. If you code transaction management in the UI then you will need to figure out how it could be accomplished. This is not a good thing.

In step 3, Will user1 overwrite the changes of user 2?


It depends on how you write the application and how you design transaction management.
Vivek Punekar
Greenhorn

Joined: Aug 25, 2009
Posts: 12
Thanks for the reply.

About the comment: [Transaction management should not be occuring in the UI regardless. If you code transaction management in the UI then you will need to figure out how it could be accomplished. This is not a good thing. ]
The transaction management in our case is really in the persistence layer by means of @version column.
In UI case:
1. User A clicks on List employee records: A table with employee records is displayed. User A selects first record, goes to its Edit page.
2. User B clicks on List employee records: A table with employee records is displayed. User B selects first record, goes to its Edit page.
3. User A commits his changes
4. User B commits his changes.
In my view, the action in step 4 should fail as User B was working with older version of entity (which was modified by user A in the meantime)

Please correct me or suggest.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Concurrency in Web Services
 
Similar Threads
Spring Web Flow 2 Web Development
Will this locking mechanism be allowed?
Struts idea needed
Can I recover from a optimistic lock exception within the same transaction?
Unreferenced interface should not be used.