users@glassfish.java.net

Re: concurrently modifying entity instance

From: <glassfish_at_javadesktop.org>
Date: Thu, 17 Apr 2008 08:52:36 PDT

Hello,

 At the object level, the two users will be working with two different copies of the same Resource object - maintaining transactional issolation. Changes in one will not be seen by other users until the transaction commits. If the first user comits, and the second has already loaded the resource entity, they will only see the first user's changes if the object gets refreshed. So the worry then might be that the second user overwrites the first user's changes.

You can use pessimistic locking which can prevent all other users from even reading the Resource until the lock is released (transaction commits or rollsback). This could tie up alot of threads/resources waiting for a single transaction to complete, so more comonly optimistic locking is used by adding a version field. This would result in the second user to commit getting an optimistic lock exception if they attempt to overwrite with stale data. When they receive one, they just need to refresh and try again.
[Message sent by forum member 'chris_delahunt' (chris_delahunt)]

http://forums.java.net/jive/thread.jspa?messageID=269790