1 2 Previous Next 25 Replies Latest reply on Aug 23, 2011 7:44 AM by ashok.ashok.k.vedainformatics.com

    Quartz Scheduling questions

    risenhoover

      Hi All,


      First, I'd like to congratulate the seam team on a job well done.  I've been prototyping a new system and have been able to make some massive progress with a lot less effort than I expected.


      That said, I'm stuck on a problem that has to do with the Quartz scheduler. 


      I have two basic questions:


      1.  I'd like to kick off a number of processes when the web application starts.  These processed would run every few minutes and so some stuff.  I can't find any documentation that describes how to do this.  This is the ultimate goal...


      2.  That said, I can't even get a process schedule by manually starting it through an action.  I have reviewed the seam examples extensively, and I'm obviously missing something.  I simply don't see how, or where, the task is actually created.


      If you look at the Seam Quartz example, the PaymentController calls the PaymentProcessor.schedulePayment method with some scheduling information.  The schedulePayment method takes some parameters that are annotated, and performs some processes, then returns null.


      I have tried to mimic this exactly, except that my method only takes an @IntervalCron as a parameter (since it's a long-running process).


      When I click on the Action, the method that should be scheduled executes immeditely, but never again.


      Here's some code:


      This is the action that's called by the GUI:


      public void startCrawlersAction() {

        QuartzTriggerHandle handle =
         crawler.scheduleCrawl("0 * * * * ?");
      }

      And here's the code that's supposed to perform the action on a regular basis:


      @Asynchronous
      public QuartzTriggerHandle scheduleCrawl(@IntervalCron, String cron) {

        log.info("Scheduling crawler with " + cron + " cron schedule");

        this.crawlFeeds();
      return null;
      }


      Any advice would be appreciated.

        • 1. Re: Quartz Scheduling questions
          nickarls
          • 2. Re: Quartz Scheduling questions
            risenhoover

            This definitely helps solve the first problem!  Now if only I could figure out the quartz part...  Thanks!

            • 3. Re: Quartz Scheduling questions

              Paul: Could you provide the classes containing both crawler and scheduleCrawl methods? (and please use the code block feature).


              I have experienced the same thing you describe (immediate excecution, and the none at all) when being in the same class with caller and async method.

              • 4. Re: Quartz Scheduling questions
                risenhoover

                Here's the code from my components.xml file that's relevant to the timers...



                <!-- I've tried both of these...
                  <async:quartz-dispatcher />
                -->
                <async:timer-service-dispatcher />



                Here's the code that is supposed to kick off the scheduler. I'm happy to say that it wakes up and executes when the application starts.



                @Observer("org.jboss.seam.postInitialization")
                public void scheduleCrawlers() {
                
                  log.info("Scheduling crawlers");
                          
                  // every thirty seconds...
                  QuartzTriggerHandle handle = scheduleCrawl(30000l);
                
                }



                It executes the following code immediately, and then never again...



                @Asynchronous
                public QuartzTriggerHandle scheduleCrawl(@IntervalDuration,
                    Long interval) {
                
                  log.info("Scheduling crawler with " + interval + " interval schedule");
                  this.crawlFeeds();
                  return null;
                }
                



                One thing that's curious is that Eclipse is pointing out an error in the components.xml file that appears to be related to the async: tag.  Here's what it tells me...




                cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'async:timer-service-dispatcher'.


                I get the same message no matter whether I've got the quartz scheduler or the EJB scheduler.


                Thanks!





                • 5. Re: Quartz Scheduling questions
                  risenhoover

                  OK So I tried move the scheduling method into a separate Seam component but it still doesn't work.  The symptoms remain the same.  Upon initialization the crawler runs once, then never again.


                  I really think the problem is related to the error I'm getting in the components.xml file.  No matter which timer I use (quartz, EJB3, or the JVM timer), Eclipse reports the error I outlined in my last posting...


                  Any help??  Anyone?

                  • 6. Re: Quartz Scheduling questions

                    Have you declared the async namespace? That is, do you have the following definition in the top of the components.xml.
                    (Look for async)


                    <components xmlns="http://jboss.com/products/seam/components" xmlns:core="http://jboss.com/products/seam/core"
                         xmlns:persistence="http://jboss.com/products/seam/persistence" xmlns:transaction="http://jboss.com/products/seam/transaction"
                         xmlns:mail="http://jboss.com/products/seam/mail" xmlns:security="http://jboss.com/products/seam/security" xmlns:async="http://jboss.com/products/seam/async"
                         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:web="http://jboss.com/products/seam/web"
                         xsi:schemaLocation="http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd 
                                     http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd
                                     http://jboss.com/products/seam/async http://jboss.com/products/seam/async-2.0.xsd 
                                     http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.0.xsd 
                                     http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd
                                     http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.0.xsd
                                     http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.0.xsd
                                     http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd">
                    
                    


                    • 7. Re: Quartz Scheduling questions
                      risenhoover

                      Yes I had to manually add that.

                      • 8. Re: Quartz Scheduling questions

                        So now everything works, right?

                        • 9. Re: Quartz Scheduling questions
                          risenhoover

                          Sigh No, sorry.  I had manually added the async namespace a while ago, sorry that my response was a bit misleading.  The behavior is the same.  Executes once at startup, then never again.

                          • 10. Re: Quartz Scheduling questions

                            Could you paste your components.xml? The error message you get is the same I get in eclipse if I remove the namespace


                            xmlns:async="http://jboss.com/products/seam/async"
                            



                            or the schemaLocation


                            http://jboss.com/products/seam/async http://jboss.com/products/seam/async-2.0.xsd 
                            

                            • 11. Re: Quartz Scheduling questions
                              risenhoover

                              <?xml version="1.0" encoding="UTF-8"?>
                              <components xmlns="http://jboss.com/products/seam/components"
                                   xmlns:core="http://jboss.com/products/seam/core"
                                   xmlns:persistence="http://jboss.com/products/seam/persistence"
                                   xmlns:drools="http://jboss.com/products/seam/drools"
                                   xmlns:bpm="http://jboss.com/products/seam/bpm"
                                   xmlns:security="http://jboss.com/products/seam/security"
                                   xmlns:async="http://jboss.com/products/seam/async"
                                   xmlns:mail="http://jboss.com/products/seam/mail"
                                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                   xsi:schemaLocation="http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd 
                                               http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd 
                                               http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.0.xsd
                                               http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.0.xsd
                                               http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd
                                               http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.0.xsd
                                               http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd">
                              
                                   <core:init debug="true" jndi-pattern="@jndiPattern@" />
                              
                                   <core:manager concurrent-request-timeout="500"
                                        conversation-timeout="120000" conversation-id-parameter="cid"
                                        parent-conversation-id-parameter="pid" />
                              
                                   <persistence:managed-persistence-context name="entityManager"
                                        auto-create="true"
                                        persistence-unit-jndi-name="java:/lykitEntityManagerFactory" />
                              
                                   <drools:rule-base name="securityRules">
                                        <drools:rule-files>
                                             <value>/security.drl</value>
                                        </drools:rule-files>
                                   </drools:rule-base>
                              
                                   <security:identity security-rules="#{securityRules}"
                                        authenticate-method="#{authenticator.authenticate}"
                                        remember-me="true" />
                              
                                   <event type="org.jboss.seam.security.notLoggedIn">
                                        <action execute="#{redirect.captureCurrentView}" />
                                   </event>
                                   <event type="org.jboss.seam.security.loginSuccessful">
                                        <action execute="#{redirect.returnToCapturedView}" />
                                   </event>
                              
                                   <mail:mail-session host="localhost" port="2525" username="test"
                                        password="test" />
                              
                                   <!-- For use with jBPM pageflow or process management -->
                                   <!--  
                                        <bpm:jbpm>
                                        <bpm:process-definitions></bpm:process-definitions>
                                        <bpm:pageflow-definitions></bpm:pageflow-definitions>
                                        </bpm:jbpm>
                                   -->
                              
                                   <!--       <async:quartz-dispatcher />
                                   <async:thread-pool-dispatcher />
                                   -->
                                        <async:timer-service-dispatcher />
                                   
                              </components>
                              


                              • 12. Re: Quartz Scheduling questions
                                risenhoover

                                OK Progress!  I re-read your last message and realized that I didn't have the schemaLocation.  I added that and the compile-time error has gone away.  I still don't see the process repeating though.


                                So, if you could clarify one thing, the Long number that is annotated as the @IntervalDuration -- that's in milliseconds, right?  And am I required to provide an @Expiration or a @FinalExpiration if I want the process to start immediately and continue forever?

                                • 13. Re: Quartz Scheduling questions
                                  risenhoover

                                  Ok I'm beginning to answer my own questions now.  From the docs it appears that the @Expiration tag is when the timer first kicks off the initial call, and it looks like it's required.  I've added that with a value of now and it's still not repeating.  I also added the @FinalExpiration with a date of two years from now and still nothing.


                                  I'm going to try switching to a cron timer to see if that helps...

                                  • 14. Re: Quartz Scheduling questions
                                    zahidmaqbool

                                    Hi Paul,


                                    I also had a similiar problem like yours..


                                    But then when i moved my scheduler method to another class with @AutoCreate it all works perfect now.


                                    I still cant understand how can that help me.


                                    It works, but I just cant figure out why it works in a seperate class and not in the same one.

                                    1 2 Previous Next