10 Replies Latest reply on Mar 22, 2006 1:17 PM by Jens Elkner

    How to protect an object from concurrent access in EJB3.0 ?

    song hao Newbie

      The synchronized keyword in Java allows you to protect an object from concurrent access.but how to protect an object from concurrent access in EJB3.0?
      for example:
      a Stateless EJB access a Entity Instance.

      @Stateless
      @Local(AirlineManager.class)
      public class AirlineManagerBean implements AirlineManager {
       ........
      
       public boolean update(UpdateBean airline) {
       ...........
       try {
       Airline ca = em.find(Airline.class, "HK");
       ..........
       em.merge(ca);
       ...........
       } catch(Exception e) {
       ..........
       }
       }
      
      }

      When two AirlineManagerBean Instance to update the same Airline Instance("HK") at the same time, it throw a Exception about write lock.

      IN JBoss 4.0.4RC1 and EJB 3.0 RC5, I can't catch this Exception via try-catch keyword.

      How to protect this complexion:
      At the same time, one want to update "HK" Airline instance's field "SeatID" to "17A", another one want to update the same "HK" Airline instance's field "BaggageID" to "NG54278". How to solve this clash.