4 Replies Latest reply on Dec 20, 2012 2:14 PM by tony.herstell1

    @Schedule delay before initial firing....

    tony.herstell1

      I have this:

       

      @Schedule(minute = "*/5", hour = "*", persistent = false) // every 5 mins

       

      But I want to have a delay before the first trigger fires.

       

      I have 2MB of data importing through Hiberantes import.sql.... which is taking some time.

       

      Is there a way??

       

      e.g.

      @Schedule(minute = "*/5", hour = "*", persistent = false, initial_delay_minute="10")

        • 1. Re: @Schedule delay before initial firing....
          nickarls

          I don't think(tm) it can be done with Schedule. TimerService has some functionality for it but you could always timestamp in @PostConstruct and exit early if enough delay has not been reached...

          • 2. Re: @Schedule delay before initial firing....
            sfcoy

            You could also try injecting an EntityManager into the EJB with the @Schedule annotation. This may delay it's deployment until Hibernate is fully initialised.

            • 3. Re: @Schedule delay before initial firing....
              jaikiran

              Or you can keep it more within your code and in the @Schedule method, look for some field in the DB or some other place which tells you whether or not the DB import is done. If it isn't then just return from that @Schedule method and since it fires every few minutes, you don't have to worry about rescheduling it.

              • 4. Re: @Schedule delay before initial firing....
                tony.herstell1

                All great solutions.

                Thanks... I guess I should have "thought" before I asked.

                Sadly common sense is not common.

                 

                > don't think(tm) it can be done with Schedule. TimerService has some functionality for it but you could always timestamp in @PostConstruct and exit early if enough delay has not been reached...

                Nice solution

                 

                > You could also try injecting an EntityManager into the EJB with the @Schedule annotation. This may delay it's deployment until Hibernate is fully initialised.

                I am wary of this as the framework writers go and change stuff like that...

                 

                > look for some field in the DB

                Nice solution too

                I used this pattern for "batching".

                 

                I suppose I also asked beacuse it sort of a nice feature request as I needed it and it wasn't there.