Announcement Announcement Module
Collapse
No announcement yet.
SchedulerFactoryBean does not start Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • SchedulerFactoryBean does not start

    When I load up my application, I want my Quartz scheduling job to start automatically.

    But somehow this doesn't work. I need to manually start the SchedulerFactoryBean in my code.

    Here is what is in my application context:

    <!-- Quartz -->
    <bean name="mailJob" class="org.springframework.scheduling.quartz.JobDe tailBean">
    <property name="jobClass" value="my.package.scheduling.quartz.MailJob"/>
    </bean>

    <bean id="simpleTrigger" class="org.springframework.scheduling.quartz.Simpl eTriggerBean">
    <property name="jobDetail" ref="mailJob"/>
    <property name="startDelay" value="2000"/>
    <property name="repeatInterval" value="10000"/>
    </bean>

    <bean id="scheduler" class="org.springframework.scheduling.quartz.Sched ulerFactoryBean">
    <property name="triggers">
    <list>
    <ref bean="simpleTrigger"/>
    </list>
    </property>
    </bean>

    Can anyone explain to me why my scheduler does not automatically start?

    Thank you.
    Last edited by springzilla; Jun 1st, 2007, 09:45 AM.

  • #2
    I have solved the problem myself. I added the lazy-init="false".

    <bean id="scheduler" class="org.springframework.scheduling.quartz.Sched ulerFactoryBean" lazy-init="false">
    <property name="triggers">
    <list>
    <ref bean="simpleTrigger"/>
    </list>
    </property>

    Comment


    • #3
      This is the default setting, so I'm not sure how that would have solved your problem.
      The default behavior for ApplicationContext implementations is to eagerly pre-instantiate all singleton beans at startup.
      http://www.springframework.org/docs/...tory-lazy-init
      Last edited by karldmoore; Aug 27th, 2007, 02:29 PM.

      Comment


      • #4
        Facing the same issue

        Hi all,

        I am facing the same issue as mentioned above. I am using Spring 2.0.6 on JDk 1.5.0_06 on Windows. My bean configuration is as:

        Code:
        <beans>
            <bean name="myJob" 
                  class="org.springframework.scheduling.quartz.JobDetailBean">
                <property name="jobClass" value="subho.ExampleJob"/>
            </bean>
            
            <bean id="simpleTrigger" 
                  class="org.springframework.scheduling.quartz.SimpleTriggerBean">
                <property name="jobDetail" ref="myJob"/>
                <property name="repeatInterval" value="10000"/>
            </bean>
            
            <bean id="scheduler"
                    class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
                <property name="triggers">
                    <list>
                        <ref bean="simpleTrigger"/>
                    </list>
                </property>
            </bean>
        </beans>
        In my application, I load the bean factory as:
        Code:
        public class Main {
            public static void main(String[] args) throws Exception {
                ClassPathResource resource = new ClassPathResource("config.xml");
                BeanFactory factory = new XmlBeanFactory(resource);
                
                // Without this line, it does not seem to work!
                System.out.println("Scheduler = " + factory.getBean("scheduler"));
                
                while (true) {
                    System.out.println("Main thread going to sleep for a bit");
                    Thread.sleep(1000 * 10);
                    System.out.println("Is the job running?");
                }
            }
        }
        Without the factory.getBean("scheduler") call, the job does not run. Why is it that the SchedulerFactory bean does not get initialized without me nudging it?

        Please find a standalone Eclipse project attached, if someone wants to try the code (please see lib\libs_needed.txt though).

        Thanks,
        Binil

        Comment


        • #5
          Hey

          Add lazy-init="false" to your scheduler bean. That solved the problem for me.

          Like this:

          <bean "scheduler"class="org.springframework.scheduling.q uartz.SchedulerFactoryBean" lazy-init="false">>
          <property name="triggers">
          <list>
          <ref bean="simpleTrigger"/>
          </list>
          </property>
          </bean>

          Comment


          • #6
            Nope that did not work for me.

            Comment


            • #7
              Had a read of this?
              http://www.springframework.org/docs/...tory-lazy-init
              Last edited by karldmoore; Aug 27th, 2007, 02:29 PM.

              Comment


              • #8
                karldmoore,

                Your post is very cryptic. As of now, I am taking it as a politely-worded RTFM. Yes, I read thru the relevant portion of the documentation. My configuration file is written with the following intent:
                1. All bean are singletons (the default value of singleton=true)
                2. No beans are lazy initialized (the default value of lazy-int=false)
                3. The container should eagerly initialize all beans (the default value of default-lazy-init=false)

                Kindly read through my configuration (from my previous post) and let me know if my assumptions hold good.

                If my configuration is correct, the container should have pre-initialized the beans as per the documentation snippet you posted. Is there anything that I am missing?

                Thanks,
                Binil

                Comment


                • #9
                  Sorry if it was cryptic that wasn't my intent . The documentation I was referring to was that the ApplicationContext eagerly pre-instantiates singleton beans. Hence the scheduler would be started when you create the context. You are currently using BeanFactory instead, hence you aren't seeing the required behaviour.
                  The default behavior for ApplicationContext implementations is to eagerly pre-instantiate all singleton beans at startup. Pre-instantiation means that an ApplicationContext will eagerly create and configure all of its singleton beans as part of its initialization process.
                  Try updating the code as follows.
                  Code:
                  ApplicationContext factory = new ClassPathXmlApplicationContext ("config.xml" );
                  Last edited by karldmoore; Aug 27th, 2007, 02:29 PM.

                  Comment


                  • #10
                    Have you tried;

                    <property name="autoStartup">
                    <value>true</value>
                    </property>

                    Comment


                    • #11
                      Isn't that the default?
                      http://www.springframework.org/docs/...artup(boolean)
                      Last edited by karldmoore; Aug 18th, 2007, 05:35 PM.

                      Comment


                      • #12
                        Did this solve you problem in the end?
                        Last edited by karldmoore; Aug 18th, 2007, 05:35 PM.

                        Comment


                        • #13
                          Yes, that worked

                          karldmoore,

                          Apologies for the delayed posting. I got distracted and drifted into few other tasks.

                          Yes, your suggestion worked. My code now looks like:
                          Code:
                          ApplicationContext factory = new ClassPathXmlApplicationContext ("config.xml" );
                                  
                          while (true) {
                              System.out.println("Main thread going to sleep for a bit");
                              Thread.sleep(1000 * 10);
                              System.out.println("Is the job running?");
                          }
                          and it works as expected.

                          Thank you very much!

                          Comment

                          Working...
                          X