Results 1 to 2 of 2

Thread: Quartz scheduler: implementation using JobDetailBean is not working

  1. #1

    Default Quartz scheduler: implementation using JobDetailBean is not working

    Hello,

    I'm trying to set up clustered scheduling with Spring 2.5.4 with Quartz 1.6.6 and Weblogic. For some reason the scheduler is not working: in the application's logs, I have enabled debug logging and the job in question is not writing any debug information to the logs when it used to previously. I have found no error messages in any log that I can find.

    I previously used a org.springframework.scheduling.quartz.MethodInvoki ngJobDetailFactoryBean to do the scheduling but due to errors raised when introducing a quartz.properties file, I've had to use another approach.

    My Spring application context looks like this:

    Code:
    <!-- myService is the Java class I'd like to run -->
    <bean name="myJob" class="package.MyJob">
        <property name="service" ref="myService"/>
    </bean>
    
    <bean id="jobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
        <property name="jobClass" value="package.GenericQuartzJob" />
        <property name="jobDataAsMap">
            <map>
                <entry key="batchProcessorName" value="myJob" />
            </map>
        </property>
    </bean>
    
    <bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
        <property name="jobDetail" ref="jobDetail" />
        <property name="startDelay" value="60000" />
        <property name="repeatInterval" value="60000" />
    </bean>
        
    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <ref bean="simpleTrigger" />
            </list>
        </property>
    
        <property name="applicationContextSchedulerContextKey">
            <value>applicationContext</value>
        </property>
    </bean>
    The MyJob class implements Runnable, stores the service object as an instance variable and has this method:

    Code:
    public void run() {
        this.service.myMethod();
    }
    The GenericQuartzJob extends QuartzJobBean and has this method:

    Code:
    @Override
    protected void executeInternal(final JobExecutionContext jobExecutionContext)
            throws JobExecutionException {
        try {
            SchedulerContext schedulerContext = jobExecutionContext
                    .getScheduler().getContext();
            ApplicationContext applicationContext = (ApplicationContext) schedulerContext
                    .get("applicationContext");
            Runnable processToRun = (Runnable) applicationContext
                    .getBean(this.batchProcessorName);
            processToRun.run();
        } catch (Exception exception) {
            throw new JobExecutionException("Unable to execute job: "
                    + this.batchProcessorName, exception);
        }
    }
    The quartz.properties file is added to the EAR file under WEB-INF/classes:

    Code:
    org.quartz.scheduler.instanceId=AUTO
    
    org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool
    org.quartz.threadPool.threadCount=1
    
    org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
    org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
    org.quartz.jobStore.isClustered=true
    ... and also includes connection details to the database I'm using. I have queried the database tables and it looks like the job is being run as the TIMES_TRIGGERED value for "simpleTrigger" in qrtz_simple_triggers is being incremented. But, as I say, I'm getting no debug output and the method isn't being executed.

    Thanks in advance for any assistance.

  2. #2

    Default

    Following on from this, I've managed to get a simpler but similar example to work.

    Application context file:

    Code:
    <bean name="myJob" class="org.springframework.scheduling.quartz.JobDetailBean">
      <property name="jobClass" value="package.MyJob" />
      <property name="jobDataAsMap">
        <map>
          <entry key="message" value="Hello world" />
        </map>
      </property>
    </bean>
    
    <bean id="myTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
        <property name="jobDetail" ref="myJob" />
        <property name="startDelay" value="60000" />
        <property name="repeatInterval" value="120000" />
    </bean>
    ... with the MyJob class:

    Code:
    @Override
    protected void executeInternal(final JobExecutionContext ctx) throws JobExecutionException {
        LOGGER.warn("[JOB] " + message);
    }
    This prints out "Hello world" every two minutes to the application's log on the server.

    My non-working version isn't much different, so I'm baffled as to why that one isn't working, yet this one is. Any help would be greatly appreciated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •