0 Replies Latest reply on Apr 7, 2011 1:25 AM by praveen sule

    Exception while running multiple quartz trigger at a time

    praveen sule Newbie
      Hello everyone!
              
            I am trying quartz corn trigger in seam 2.1,Hibernate,Mysql
      I have default quartz configuration.And it works fine when we are scheduling at different time.But my problem is when I am adding more than 1 job for a particular interval i am getting an error.

      for ex job1 [0 12 12 7 04 ?](corn expression)
             job2 [0 12 12 7 *  ?](corn expression)

      These both expression will trigger at same time on April 07th at 12:12:00 and call a same method at a time so i am getting an exception



      `09:46:00,015 INFO  [STDOUT] ergergergi am sending at---->>Thu Apr 07 09:46:00 IST 2011
      09:46:00,015 INFO  [STDOUT] i am sending email
      09:46:00,015 WARN  [LoadContexts] fail-safe cleanup (collections) : org.hibernate.engine.loading.CollectionLoadContext@e3044f<rs=com.mysql.jdbc.ResultSet@130e2ea>
      09:46:00,031 INFO  [TxConnectionManager] Unregistered handle that was not registered! org.jboss.resource.adapter.jdbc.jdk6.WrappedConnectionJDK6@1bc1c4b for managedConnection: org.jboss.resource.adapter.jdbc.local.LocalManagedConnection@2c5b47
      09:46:00,031 ERROR [AsynchronousExceptionHandler] Exeception thrown whilst executing asynchronous call
      java.lang.NullPointerException
              at org.hibernate.jdbc.ConnectionManager.closeConnection(ConnectionManager.java:471)
              at org.hibernate.jdbc.ConnectionManager.aggressiveRelease(ConnectionManager.java:429)
              at org.hibernate.jdbc.ConnectionManager.afterStatement(ConnectionManager.java:304)
              at org.hibernate.jdbc.AbstractBatcher.closePreparedStatement(AbstractBatcher.java:572)
              at org.hibernate.jdbc.AbstractBatcher.closeStatement(AbstractBatcher.java:291)
              at org.hibernate.jdbc.AbstractBatcher.closeQueryStatement(AbstractBatcher.java:307)
              at org.hibernate.jdbc.AbstractBatcher.closeQueryStatement(AbstractBatcher.java:234)
              at org.hibernate.loader.Loader.doQuery(Loader.java:749)
              at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
              at org.hibernate.loader.Loader.loadCollection(Loader.java:2015)
              at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:59)
              at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:587)
              at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:83)
              at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1743)
              at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:366)
              at org.hibernate.collection.PersistentBag.clear(PersistentBag.java:387)
              at org.hibernate.type.CollectionType.replaceElements(CollectionType.java:501)
              at org.hibernate.type.CollectionType.replace(CollectionType.java:574)
              at org.hibernate.type.TypeFactory.replace(TypeFactory.java:505)
              at org.hibernate.event.def.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:392)
              at org.hibernate.event.def.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:319)
              at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:167)
              at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:81)
              at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:704)
              at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:688)
              at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:692)
              at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:235)
              at org.jboss.seam.persistence.EntityManagerProxy.merge(EntityManagerProxy.java:132)
              at org.hibernate.search.jpa.impl.FullTextEntityManagerImpl.merge(FullTextEntityManagerImpl.java:97)
              at org.jboss.seam.persistence.EntityManagerProxy.merge(EntityManagerProxy.java:132)
              at com.sec.ezeeDesk.QuartzUtils.crmMessageSheduleProcess(QuartzUtils.java:186)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
              at java.lang.reflect.Method.invoke(Unknown Source)
              at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
              at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
              at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.core.ConversationInterceptor.aroundInvoke(ConversationInterceptor.java:65)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:95)
              at org.jboss.seam.util.Work.workInTransaction(Work.java:47)
              at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:89)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.async.AsynchronousInterceptor.aroundInvoke(AsynchronousInterceptor.java:52)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
              at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
              at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
              at com.sec.ezeeDesk.QuartzUtils_$$_javassist_1.crmMessageSheduleProcess(QuartzUtils_$$_javassist_1.java)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
              at java.lang.reflect.Method.invoke(Unknown Source)
              at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
              at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
              at org.jboss.seam.async.AsynchronousInvocation$1.process(AsynchronousInvocation.java:62)
              at org.jboss.seam.async.Asynchronous$ContextualAsynchronousRequest.run(Asynchronous.java:80)
              at org.jboss.seam.async.AsynchronousInvocation.execute(AsynchronousInvocation.java:44)
              at org.jboss.seam.async.QuartzDispatcher$QuartzJob.execute(QuartzDispatcher.java:243)
              at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
              at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:529)
      09:46:00,046 ERROR [AsynchronousExceptionHandler] Exeception thrown whilst executing asynchronous call
      java.lang.IllegalStateException: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before merging: com.sec.ezeeCRM.CrmMessage
              at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:611)
              at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:244)
              at org.jboss.seam.persistence.EntityManagerProxy.merge(EntityManagerProxy.java:132)
              at org.hibernate.search.jpa.impl.FullTextEntityManagerImpl.merge(FullTextEntityManagerImpl.java:97)
              at org.jboss.seam.persistence.EntityManagerProxy.merge(EntityManagerProxy.java:132)
              at com.sec.ezeeDesk.QuartzUtils.crmMessageSheduleProcess(QuartzUtils.java:192)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
              at java.lang.reflect.Method.invoke(Unknown Source)
              at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
              at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
              at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.core.ConversationInterceptor.aroundInvoke(ConversationInterceptor.java:65)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:95)
              at org.jboss.seam.util.Work.workInTransaction(Work.java:47)
              at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:89)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.async.AsynchronousInterceptor.aroundInvoke(AsynchronousInterceptor.java:52)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
              at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
              at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
              at com.sec.ezeeDesk.QuartzUtils_$$_javassist_1.crmMessageSheduleProcess(QuartzUtils_$$_javassist_1.java)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
              at java.lang.reflect.Method.invoke(Unknown Source)
              at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
              at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
              at org.jboss.seam.async.AsynchronousInvocation$1.process(AsynchronousInvocation.java:62)
              at org.jboss.seam.async.Asynchronous$ContextualAsynchronousRequest.run(Asynchronous.java:80)
              at org.jboss.seam.async.AsynchronousInvocation.execute(AsynchronousInvocation.java:44)
              at org.jboss.seam.async.QuartzDispatcher$QuartzJob.execute(QuartzDispatcher.java:243)
              at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
              at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:529)
      Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before merging: com.sec.ezeeCRM.CrmMessage
              at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:89)
              at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:704)
              at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:688)
              at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:692)
              at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:235)
              ... 41 more
      09:58:51,140 INFO  [TxConnectionManager] Unregistered handle that was not registered! org.jboss.resource.adapter.jdbc.jdk6.WrappedConnectionJDK6@207655 for managedConnection: org.jboss.resource.adapter.jdbc.local.LocalManagedConnection@1b1886a
      `

      my quartz controller class


      `

      @Observer( "org.jboss.seam.postInitialization")
      public void observe() {
          Calendar cal = Calendar.getInstance();
          cal.set(2040, Calendar.MAY, 10);
          SystemUtils su = new SystemUtils(em);
          String paramValue =                           
      su.getSystemParamValue(SystemParams.QUARTZ_ACTIVATION_DEACTIVATION_BOOLEAN);
      System.out.println("******   QUARTZ FUNCTIONALITY  STARTED ********** ");
      boolean theValue =Boolean.parseBoolean(paramValue);
        if (theValue) {
                this.messageShedule();
                } else {
                log.info("Quartz functionallity is not started.");
              }
      }
      @SuppressWarnings( { "unchecked", "deprecation" })
      public void messageShedule() {
      System.out.println("*****this is my quartz ********");
      Calendar cal = Calendar.getInstance();
      cal.set(2040, Calendar.MAY, 10);
      messageShedule = em.createQuery(" from CrmMessageSchedule cms where 1=1 and cms.isActive =1").getResultList();
      if (messageShedule.size() > 0) {
        for (int i = 0; i < messageShedule.size(); i++) {
              CrmMessageSchedule cms = messageShedule.get(i);
      if (cms.getScheduleType().equals(CrmScheduleType.OnlyOn)) {
          Date d1 = cms.getScheduledOn();
          String minutes;
          String hours;
          ArrayList<String> str = new ArrayList<String>();            
          StringTokenizer Tok = new   
                          StringTokenizer(cms.getScheduledTime(), ":");
              while (Tok.hasMoreTokens()) {
              String kt = Tok.nextToken();
              str.add(kt);
              System.out.println("" + kt);
              }
              System.out.println("" + str);
              if (str.size() == 2) {
              minutes = str.get(1);
              hours = str.get(0);
              } else if (str.size() == 1) {
              hours = str.get(0);
              minutes = "0";
              } else {
              minutes = "0";
              hours = "0";
              }
              d1.setHours(this.convertStringToInt(hours));
              d1.setMinutes(this.convertStringToInt(minutes));
              d1.setSeconds(0);
              Long diff = d1.getTime() - new Date().getTime();
              if (diff > 0) {
              try {
              System.out.println("triggering????????");
              QuartzTriggerHandle handle =
                 quartzProcessor.crmMessageSheduleProcess(new Date(),
                 cms.cornExpression(), d1, cms.getMessageId());
                 cms.setQuartzTriggerHandle(null);
                 cms.setQuartzTriggerHandle(handle);
              } catch (Exception ex) {
              ex.printStackTrace();
              }
              }
              } else {
              try {
              System.out.println("triggering????????");
              QuartzTriggerHandle handle =
              quartzProcessor.crmMessageSheduleProcess(new Date(),
              cms.cornExpression(), cal.getTime(), cms.getMessageId());
              cms.setQuartzTriggerHandle(null);
              cms.setQuartzTriggerHandle(handle);
              } catch (Exception ex) {
              ex.printStackTrace();
              }
              }
              }
              }
              }
              public int convertStringToInt(String str) {
                      try {
                              int i = Integer.parseInt(str.trim());
                              return i;
                      } catch (NumberFormatException nfe) {
           System.out.println("NumberFormatException: " + 
                 nfe.getMessage());
              }
                      return 0;
              }

        public SystemUtils getSystemUtils() {
                      return systemUtils;
              }
        public void setSystemUtils(SystemUtils systemUtils) {
                      this.systemUtils = systemUtils;
              }

        public List<CrmMessageSchedule> getMessageShedule() {
                      return messageShedule;
              }

        public void setMessageShedule(List<CrmMessageSchedule>
                                           messageShedule) {
        this.messageShedule = messageShedule;
              }`


      and this is my quartz processor class


      `
      @SuppressWarnings( "unchecked")
      @Asynchronous
      @Transactional
      @TransactionAttribute( TransactionAttributeType.REQUIRES_NEW)
      public QuartzTriggerHandle crmMessageSheduleProcess(@Expiration
              Date when, @IntervalCron
              String interval, @FinalExpiration
              Date endDate, CrmMessage crmMessage) {
             QuartzTriggerHandle handle = new 
                                    QuartzTriggerHandle("AFSTrigger");
            List<CrmMessage> list = new ArrayList<CrmMessage>();
             crm = em.merge(crmMessage);
              if (crm != null) {
              System.out.println(crm.getMessageTopic() + "i am sending at---->>" + new Date());
            if (crm.getIsEmailSelected()) {
              System.out.println("i am sending email");
              list.add(crm);
              sendConfirmationMail(em.merge(crmMessage));
              System.out.println("i am out email");
              }
              if (crm.getIsSMSSelected()) {
              System.out.println("i am sending SMS");
              sendSMSMessage(em.merge(crmMessage));
              System.out.println("i am out SMS");
              }
              }
              return handle;
              }
      @Begin( join = true)
          public void sendConfirmationMail(CrmMessage crmMessage) {
          CrmMessageSentHistory history = new CrmMessageSentHistory();
          history.setMessageId(crmMessage);
          history.setSentOn(new Date());
          em.persist(history);
          List<String> mailList = new ArrayList<String>();
          for (CrmCustomerList customerList :
                              em.merge(crmMessage).getCustomerList()) {
          for (CrmCustomerListContent cclc :
                     em.merge(customerList).getCustomerListContent()) {
         if (cclc.getEmail() != null &&
                                 cclc.getEmail().trim().length() > 0) {
         mailList.add(cclc.getEmail());
         System.out.println("mail ids--------->>>>" + cclc.getEmail());
         } else {
          CrmMessageSentFailed failed = new CrmMessageSentFailed();
          failed.setCrmMessageSentHistory(history);
          failed.setResPassenger(cclc.getReservationPassenger());
          em.persist(failed);
        }
      }
      }
      HashMap<String, Object> mailData = new HashMap<String, Object>();
      String str = "praveen.sule@gmail.com";
      mailData.put("ccAddress", str);
      mailData.put("toAddress", mailList);
      mailData.put("subject", crmMessage.getSubject());
      mailData.put("content", crmMessage.getContent());
      mailData.put("imageData", crmMessage.getGuestResource());
      Events.instance().raiseAsynchronousEvent("send-mail", "/ezeeCRM/crmMail.jsp", mailData);
      }`

      when a trigger fires it works fine and sends the message but when more than a trigger fires at a time I am getting this exception .

      Please help me out to solve this problem.
      Thanks in advance.