Search code examples
javajakarta-eeconcurrencyjava-ee-6

Java EE - Parallel editing, multiple users, any ideas?


I need to implement some mechanism to prevent users from editing same objects in the same time. Here's my application flow:

  1. Go to 'list' page
  2. Select row to edit form datatable
  3. Click edit button (navigation to 'edit' page)
  4. Change data
  5. Click 'Save' or 'Cancel' (navigation back to 'list' page)

I wish I could check at step 3. if another user is editing same record (same id) and display information e.g. 'Sorry, another user is editing this'.

My idea is to keep map of logged users and table names + ids, which they currently edit. I would use application scoped bean (e.g. EJB 3.1 @Singleton) for this purpose. Can you point weaknesses of this solution? Can you propose any other?

I use Java EE 6, Seam3, Glassfish 3 and Oracle DB 11. I use MyBatis, no JPA frameworks.


Solution

  • You would be much better off having some sort of mechanism to accept well identified changes, and when applying changes, detect if the change was initiated on a different copy of the data than now exists, and raise an exception.

    This kind of work flow prevents the dreaded, "I can't save the company because someone in CA started to change the critical record but then went to lunch."

    Read the first few chapters of the Subversion book. While you are currently not concerned with data version control, the conflict scenarios are more complete, and better thought out than the old "library" system, where shared items are not available as long as they are in possession of one person.