9 Replies Latest reply on Oct 27, 2010 4:25 AM by Roman Mandeleil

    IntervalDuration is neglected

    Roman Mandeleil Newbie

      I have a  time set by @IntervalDuration parameter. No matter what the
      timer is being set it triggers every second. Any enlightenings ?

        • 1. Re: IntervalDuration is neglected
          Nikolay Elenkov Master

          Show components.xml and relevant code if you wish to be enlightened :)

          • 2. Re: IntervalDuration is neglected
            Roman Mandeleil Newbie

            Sure, here it is. Now enlighten me :)



            component.xml




            <components xmlns="http://jboss.com/products/seam/components" 
                 xmlns:core="http://jboss.com/products/seam/core" 
                 xmlns:security="http://jboss.com/products/seam/security"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xmlns:mail="http://jboss.com/products/seam/mail"
                xmlns:async="http://jboss.com/products/seam/async"
                 xmlns:persistence="http://jboss.com/products/seam/persistence" 
                 xsi:schemaLocation="http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd
                             http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
                             http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.1.xsd
                             http://jboss.com/products/seam/persistence http://www.jboss.com/products/seam/persistence-2.0.xsd">
            
            
            
                 <security:identity authenticate-method="#{authenticator.authenticate}" />
            
            
                 <core:init jndi-pattern="tantra/#{ejbName}/local" debug="true" />
            
                 <core:manager concurrent-request-timeout="20000"
                      conversation-timeout="200000" conversation-id-parameter="id"
                      default-flush-mode="MANUAL" />
            
            
                <persistence:managed-persistence-context name="entityManager" auto-create="true" 
                     entity-manager-factory="#{tantra_regEntityManagerFactory}" 
                     scope="session" />
            
                <persistence:managed-persistence-context name="applicationEntityManager" auto-create="true" 
                     entity-manager-factory="#{tantra_regEntityManagerFactory}" 
                     scope="application" />
            
                 <persistence:entity-manager-factory name="tantra_regEntityManagerFactory" 
                      persistence-unit-name="tantra_persistent_unit"/>
            
            
            
                      
                 <async:timer-service-dispatcher/>
            
            
            
            
            </components>






            StartTriger.java




            
            
            
            import javax.persistence.EntityManager;
            
            import org.jboss.seam.ScopeType;
            import org.jboss.seam.annotations.Create;
            import org.jboss.seam.annotations.In;
            import org.jboss.seam.annotations.Logger;
            import org.jboss.seam.annotations.Name;
            import org.jboss.seam.annotations.Observer;
            import org.jboss.seam.annotations.Scope;
            import org.jboss.seam.annotations.Startup;
            import org.jboss.seam.async.QuartzTriggerHandle;
            import org.jboss.seam.log.Log;
            import org.jboss.seam.web.ServletContexts;
            
            
            
            @Name("startTriger")
            @Scope(ScopeType.APPLICATION)
            @Startup
            public class StartTriger {
                 
            
                 @Logger
                 private static Log log;
            
                 
                 @In(required = true, scope=ScopeType.APPLICATION)
                 TimerHandler timerHandler;
                 
                 @SuppressWarnings("unused")
                 private QuartzTriggerHandle triggerHandle = null;
                 
                 
                 @Create
                 public void initTimer(){
                      
                      
                      log.info("StartTriger.initTimer");
                      log.info("StartTriger.initTimer");
                      log.info("StartTriger.initTimer");
                      
                      Long interval = 180000L;
                      
                      log.info("Interval: {0}", interval);
                      
                      timerHandler.schedulePayment(interval);
                 }
            }
            




            Timer.Handler.java


            
            import java.util.List;
            
            import javax.persistence.EntityManager;
            
            import org.jboss.seam.ScopeType;
            import org.jboss.seam.annotations.In;
            import org.jboss.seam.annotations.Logger;
            import org.jboss.seam.annotations.Name;
            import org.jboss.seam.annotations.Scope;
            import org.jboss.seam.annotations.Startup;
            import org.jboss.seam.annotations.Transactional;
            import org.jboss.seam.annotations.async.Asynchronous;
            import org.jboss.seam.annotations.async.IntervalDuration;
            import org.jboss.seam.log.Log;
            
            
            @Name("timerHandler")
            @Scope(ScopeType.APPLICATION)
            @Startup
            public class TimerHandler {
                 
                 @Logger
                 private static Log log;
            
                 @In
                 EntityManager applicationEntityManager;
                 
                 @Asynchronous
                public void schedulePayment(@IntervalDuration Long interval){ 
                 
            
                      log.info("timeout: applicationEntityManager = {0}", applicationEntityManager);
                                
                 }
                 
            
            }
            
            





            • 3. Re: IntervalDuration is neglected
              Nikolay Elenkov Master

              TimerService jobs are persistent, so if you did it once with interval one second and didn't delete the timer explicitly, it will keep on running even after server restarts. Calling schedulePayment will add new timers. Try removing <async:timer-service-dispatcher/> and test it.


              HTH


              • 4. Re: IntervalDuration is neglected
                Roman Mandeleil Newbie

                Doesn't help, by the way can I see this timer somewhere in JMX ?

                • 5. Re: IntervalDuration is neglected
                  Nikolay Elenkov Master

                  Should be there somewhere, search for TimerService. You can also inject an instance of the TimerService in your code and call getTimers() to check what timer are registered and cancel them.


                  Cf. http://download.oracle.com/javaee/5/api/javax/ejb/TimerService.html


                  • 6. Re: IntervalDuration is neglected
                    Roman Mandeleil Newbie

                    Ok I found that: EJBTimerService.listTimerHandles() - shows the timers and
                    clearTimers() clears them.


                    I don't know if it is a bug but even if I delete the application all the
                    persistence timers stays.

                    • 7. Re: IntervalDuration is neglected
                      Nikolay Elenkov Master

                      Persistent here means saved in DB. By default that's an HSQLDB JBoss uses for what not. Should be in server/default/data/hypersonic/localDB.data, IIRC, there is a Timers table. It's not a bug, it's in the JEE 5 spec.


                      • 8. Re: IntervalDuration is neglected
                        Nikolay Elenkov Master

                        In JEE 6 there is a flag to create transient timers, but the default is persistent.

                        • 9. Re: IntervalDuration is neglected
                          Roman Mandeleil Newbie

                          Ok, The topic is closed.
                          Thanks.