Link to home
Create AccountLog in
Avatar of Waponi
Waponi

asked on

Quartz Spring Scheduler Startup ?

Hello,
I am attemptint to implement the scheduler example in;
http://static.springsource.org/spring/docs/2.0.x/reference/scheduling.html
I dont see any consol output indicating the scheduler has started or the job executing .

Any Ideas ?

I have the following config
---------------------------------------------------------------------------------------------------------------------------------------
<beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:util="http://www.springframework.org/schema/util"
      xmlns:task="http://www.springframework.org/schema/task"
      
      xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/util
    http://www.springframework.org/schema/task
     
    http://www.springframework.org/schema/task/spring-task-3.0.xsd
    http://www.springframework.org/schema/util/spring-util-3.0.xsd" default-lazy-init="true">
 
 <bean name="exampleJob" class="org.springframework.scheduling.quartz.JobDetailBean">
  <property name="jobClass" value="com.cme.clearing.citps.querymanager.web.ExampleJob" />
  <property name="jobDataAsMap">
    <map>
      <entry key="timeout" value="5" />
    </map>
  </property>
</bean>

 <bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
    <!-- see the example of method invoking job above -->
    <property name="jobDetail" ref="jobDetail" />
    <!-- 10 seconds -->
    <property name="startDelay" value="10000" />
    <!-- repeat every 50 seconds -->
    <property name="repeatInterval" value="10000" />
</bean>

<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
    <property name="jobDetail" ref="exampleJob" />
    <!-- run every morning at 6 AM -->
    <property name="cronExpression" value="0 0 6 * * ?" />
</bean>
 
 
 <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="triggers">
        <list>
            <ref bean="cronTrigger" />
            <ref bean="simpleTrigger" />
        </list>
    </property>
</bean>
 
---------------------------------------------------------------------------------------------------------------------------------------
for class

package com.cme.clearing.citps.querymanager.web;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

public class ExampleJob extends QuartzJobBean {

        private int timeout;
        
        /**
         * Setter called after the ExampleJob is instantiated
         * with the value from the JobDetailBean (5)
         */
        public void setTimeout(int timeout) {
          this.timeout = timeout;
        }
        
        protected void executeInternal(JobExecutionContext ctx) throws JobExecutionException {
                  System.out.println(" From scheduler JobRunnerController  Running job now....");
        }
      }
Avatar of Waponi
Waponi

ASKER

Updated,
I changed <property name="jobDetail" ref="exampleJob" /> and now I see a message that the scheduler has stsrted, but no jobs get created ....

<bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
    <!-- see the example of method invoking job above -->
    <property name="jobDetail" ref="exampleJob" />   <!-- 10 seconds -->
    <property name="startDelay" value="10000" />
    <!-- repeat every 50 seconds -->
    <property name="repeatInterval" value="10000" />
</bean>

The log put out the following, then nothing from the scheduler


Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
  NOT STARTED.
  Currently in standby mode.
  Number of jobs executed: 0
  Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
  Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
>     <property name="jobDetail" ref="exampleJob" />

did you change that in *both* triggers?
Avatar of Waponi

ASKER

OK,
got the scehduler running by adding 'QuartzInitializer' to web.xml, but the jobs scheduled in applicationContext.xml are not getting created...........
What am i Missing ?
Thanks.

----------------------- web.xml ---------------------------------------------------------
<servlet>
<display-name>
Quartz Initializer Servlet
</display-name>
<servlet-name>QuartzInitializer</servlet-name>
<servlet-class>org.quartz.ee.servlet.QuartzInitializerServlet</servlet-class>
<init-param>
<param-name>shutdown-on-unload</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>start-scheduler-on-load</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

----------------------- web.xml ---------------------------------------------------------
----------------------- applicationContext.xml ---------------------------------------------------------
 
 <bean name="exampleJob" class="org.springframework.scheduling.quartz.JobDetailBean">
  <property name="jobClass" value="com.cme.clearing.citps.querymanager.web.ExampleJob" />
  <property name="jobDataAsMap">
  <map>
  </map>
  </property>
</bean>

<bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
    <property name="jobDetail" ref="exampleJob" />
    <property name="startDelay" value="10000" />
    <property name="repeatInterval" value="10000" />
</bean>

 <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="triggers">
        <list>
            <ref bean="simpleTrigger" />
        </list>
    </property>
</bean>

----------------------- applicationContext.xml ---------------------------------------------------------
----------------------- java QuartzJobBean---------------------------------------------------------
package com.cme.clearing.citps.querymanager.web;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

public class ExampleJob extends QuartzJobBean {

        private int timeout;
        
        /**
         * Setter called after the ExampleJob is instantiated
         * with the value from the JobDetailBean (5)
         */
        //public void setTimeout(int timeout) {
       //   this.timeout = timeout;
       // }
        
        protected void executeInternal(JobExecutionContext ctx) throws JobExecutionException {
                  System.out.println(" ****************************************** From scheduler JobRunnerController  Running job now....");
        }
      }
Avatar of Waponi

ASKER

It appears that lazy-init="false" allows the schedulr tostart and the examle to run.....
I am not sure why this makes it all work.

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="false">      <property name="autoStartup" value="true" />
    <property name="triggers">
        <list>
            <ref bean="cronTrigger" />
            <ref bean="simpleTrigger" />
        </list>
    </property>
    <property name="overwriteExistingJobs" value="true" />  
  </bean>
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Waponi

ASKER

Thanks
Avatar of Waponi

ASKER

Sorry for the delay, changes in priority..