Maverick
Maverick

Reputation: 238

Quartz cron Job not starting

I'm using quartz scheduler for scheduling a spring batch job. The application starts without any exception but it never fires any job.

Just let me to explain my scenario:

If I run the job(with scheduler) through a main method using MapJobRepositoryFactoryBean it works perfectly, but after integration of the scheduler with spring-mvc web app it shows some version update error, after that I used "JobRepositoryFactoryBean" which uses database for storing job states.

So I added JobRepositoryFactoryBean bean and other DB changes, but it never triggers the job.

bellow is a snippet of log

    2015-02-10 19:14:45  INFO   context.support.XmlWebApplicationContext - Bean 'jobRegistry' of type [class org.springframework.batch.core.configuration.support.MapJobRegistry] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 
2015-02-10 19:14:45  INFO   jdbc.datasource.DriverManagerDataSource - Loaded JDBC driver: com.mysql.jdbc.Driver 
2015-02-10 19:14:45  INFO   launch.support.SimpleJobLauncher - No TaskExecutor has been set, defaulting to synchronous executor. 
2015-02-10 19:14:46  INFO   context.support.DefaultLifecycleProcessor - Starting beans in phase 2147483647 
2015-02-10 19:14:46  INFO   scheduling.quartz.SchedulerFactoryBean - Starting Quartz Scheduler now 
2015-02-10 19:14:46  INFO   web.servlet.DispatcherServlet - FrameworkServlet 'mvc-dispatcher': initialization completed in 2155 ms 

Here is my job configuration

<bean id="jobLauncher"
        class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
        <property name="jobRepository" ref="jobRepository" />
    </bean>

    <bean
        class="org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor">
        <property name="jobRegistry" ref="jobRegistry" />
    </bean>

    <bean id="jobRepository"
        class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean"
        p:dataSource-ref="dataSource" p:transactionManager-ref="transactionManager">
        <property name="databaseType" value="reconConfig!{batch.databaseType}" />
        <property name="isolationLevelForCreate" value="ISOLATION_DEFAULT" />
    </bean>

    <bean id="mapJobRepository"
        class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean"
        lazy-init="true" autowire-candidate="false" />

    <bean id="jobOperator"
        class="org.springframework.batch.core.launch.support.SimpleJobOperator"
        p:jobLauncher-ref="jobLauncher" p:jobExplorer-ref="jobExplorer"
        p:jobRepository-ref="jobRepository" p:jobRegistry-ref="jobRegistry" />

    <bean id="jobExplorer"
        class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean"
        p:dataSource-ref="dataSource" />

    <bean id="jobRegistry"
        class="org.springframework.batch.core.configuration.support.MapJobRegistry" />

    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="appDataSource" />
    </bean>


    <bean class="org.springframework.batch.core.scope.StepScope" />



    <bean id="reconConfigPlaceholderProperties"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="ignoreUnresolvablePlaceholders" value="true" />
        <property name="location" value="classpath:batchDb.properties" />
        <property name="placeholderPrefix" value="reconConfig!{" />
        <property name="placeholderSuffix" value="}" />
    </bean>
</beans>

It was running successfully , but after some more development it stopped working. I'm unable to figure out what exactly I changed in configuration which caused this.

Can any one please suggest the check points in using "JobRepositoryFactoryBean", If I'm missing or the problem is else where.

Upvotes: 1

Views: 3276

Answers (2)

hariprasad
hariprasad

Reputation: 585

We have had the similar or the same problem. Look into DB repository. Repository is not resistant from different instances of application server (e.g. testing and development environment). It means, when two or more applications are connected into the same DB, you can have a problem. Applications begin to pull on the time and jobs. Unregistered jobs in one application are signed as ERROR and blocked and vice versa. Two tables are important in this case. Select XXX_SCHEDULER_STATE. Is there more than one row? Than there can be conflict. (Are you not able to distinguish your APP Server? If yes, you are connected into another DB than you suppose. It is very often but trivial problem.)

Select XXX_TRIGGERS.TRIGGER_STATE is there ERROR? If yes, try to change it from any SQL tool:

update TRIGGERS set TRIGGER_STATE = 'WATING' where TRIGGER_STATE = 'ERROR';

Restart application server. If you have a luck, the failed trigger started and work after restart. If not, try to shutdown concurrent App Server or change the repository.

Upvotes: 0

Aninda Bhattacharyya
Aninda Bhattacharyya

Reputation: 1251

If this is your entire configuration for job scheduling, I believe you are missing the Cron scheduling part entirely...

 <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
 <property name="triggers">
  <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
    <property name="jobDetail" ref="jobDetail" />
    <property name="cronExpression" value="*/10 * * * * ?" />
 </bean>
</property>
</bean>

Please read through the spring doc and the quartz scheduling section here.

Upvotes: 0

Related Questions