Discussions

EJB design: Acquiring write lock problem

  1. Acquiring write lock problem (3 messages)

    I trying to determine the best way to have it that when a user is editing her/his profile that no one else can edit that profile.
    EG.
    User A clicks on edit profile. Meanwhile, the Admin clicks to edit User A's profile. Since, User A is currently editing the profile the Admin is told to try again later.

    Design Constraints
    * User profile is represented by an CMP 2.0 entity bean (with local interfaces).
    * The user profile is returned to the JSP as a value object (UserProfileDTO) from a stateless session bean

    Time-outs can be used to prevent deadlocks. But if a lease was to be used that had to be renewed say every 30 minutes, how could you do this from the thin client?

    Please do not suggest optimistic locking (versioning, timestapping) as I would like exclusive access to editing. That is, others can view the profile while it is being modified, but only one user can edit the profile at a time.

    So basically, how can I get exclusive write access and still allow read access? and how is the problem deadlocks to be solved in this situation?

    Threaded Messages (3)

  2. Acquiring write lock problem[ Go to top ]

    One simple thing that i can think of is to have a field in your db or put a variable in session(if u are developing a web based app). When ever one needs to access that particular user's record, one has to perform a lookup on this field or variable, change its status if availaible and update the same in session or db.

    Hope this helps,

    Kiran Kadambi
  3. Acquiring write lock problem[ Go to top ]

    Thanks for the reply, but it doesn't help me much. I really need to know how to implement the leasing service without deadlock problems. That is how do I implement the timeout and renewing of leases, especially from a web client (JSP/Servlet client)??
  4. Acquiring write lock problem[ Go to top ]

    "Please do not suggest optimistic locking (versioning, timestapping) as I would like exclusive access to editing."

    Ummm... perhaps pessimistic locking would work? I'm still amazed at how often this issue comes up.