0 Replies Latest reply on Jun 7, 2014 2:55 PM by masummymesingh

    @singleton EJB Concurrency Problem When use @Lock(LockType.WRITE)

    masummymesingh

      In Singleton ejb 3.2  specification is :

       

      If a method is of locking type WRITE, client access to all the singleton's methods is blocked until

      -------------------------------------------------------------------------------------------------

      1. the current client finishes its method call

      2. Or an access timeout occurs.



      so, locking type WRITE method call at a time from one caller .

      But my  app  -- @Lock(LockType.WRITE) method call from multiple client /thread at a  time .

      problem occur :

      when use @ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)


      my environment is :


      wildfly 8.0 final , ejb3.2 , jpa2.1 ,hiberante

      --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

      @Singleton

      @LocalBean

      @AccessTimeout(value = 120000)

      @ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)

      public class MySingleton {

       

          @PersistenceContext

          EntityManager em;

        

        

          @Lock(LockType.WRITE)

          public  void doServiceTest(AppUser appuser) {

              System.out.println("start----------------masum final test-----------------W");

       

              Query query = em

                      .createNativeQuery("SELECT SSNO FROM app_users  WHERE  APP_USERS_PK =(SELECT MAX(APP_USERS_PK) FROM app_users)");

              String ob = (String) query.getSingleResult();

              String ivd = ob.substring(8);

              int id = Integer.valueOf(ivd);

              String testDateString = null;

              try {

                  Date todaysDate = new Date();

                  DateFormat df = new SimpleDateFormat("MMddyyyy");

       

                  testDateString = df.format(todaysDate);

                  id++;

                  testDateString = testDateString + id;

                  System.out.println("String in dd/MM/yyyy format is: "

                          + testDateString);

                  appuser.setSsno(testDateString);

                  em.persist(appuser);

              } catch (Exception ex) {

                  System.out.println(ex);

              }

              System.out.println("End----------------masum final test-----------------W");

          }

       

      }

       

      Error :

       

       

      Error :

       

      (default task-3) Duplicate entry '06072014107' for key 'ssno'

      (default task-3) HHH000010: On release of batch it still contained JDBC statements

      ARJUNA012125: TwoPhaseCoordinator.beforeCompletion - failed for SynchronizationImple<