下面是我与Spring的quatz集成但它没有工作,即Job没有被触发。我可以看到quartz在几个MS中检查MySQL数据库,这意味着与MYSQL的连接很好,并且记录也被插入到表中,但是下面提到的Sysout不会进入控制台。请建议可能是根本原因 -
来自Spring config XML的
<bean id="myTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="5" />
<property name="maxPoolSize" value="50" />
<property name="WaitForTasksToCompleteOnShutdown" value="true" />
</bean>
<bean id="exampleBusinessObjectJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<bean name="exampleBusinessObjectJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="name" value="exampleBusinessObjectJob"/>
<property name="jobClass" value="com.aexp.mars.job.ExampleJob"/>
</bean>
</property>
<property name="cronExpression" value="0 */1 * * * ?"/>
</bean>
<bean id="exampleBusinessObjectJob" class="com.aexp.mars.job.ExampleJob">
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="applicationContextSchedulerContextKey" value="applicationContext"/>
<property name="autoStartup" value="true"/>
<property name="triggers">
<list>
<ref bean="exampleBusinessObjectJobTrigger" />
</list>
</property>
<property name="quartzProperties">
<props>
<prop key="org.quartz.scheduler.instanceName">MARS_SCHEDULER</prop>
<prop key="org.quartz.scheduler.instanceId">AUTO</prop>
<prop key="org.quartz.scheduler.instanceId">10000</prop>
<prop key="org.quartz.scheduler.instanceId">600000</prop>
<prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>
<prop key="org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread">true</prop>
<prop key="org.quartz.threadPool.threadCount">3</prop>
<prop key="org.quartz.threadPool.threadPriority">5</prop>
<prop key="org.quartz.jobStore.misfireThreshold">60000</prop>
<prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreTX</prop>
<prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.StdJDBCDelegate</prop>
<prop key="org.quartz.jobStore.useProperties">false</prop>
<prop key="org.quartz.jobStore.dataSource">marsDS</prop>
<prop key="org.quartz.jobStore.tablePrefix">QRTZ_</prop>
<prop key="org.quartz.jobStore.isClustered">true</prop>
<prop key="org.quartz.jobStore.clusterCheckinInterval">15000</prop>
<prop key="org.quartz.jobStore.maxMisfiresToHandleAtATime">20</prop>
<prop key="org.quartz.dataSource.marsDS.driver">com.mysql.jdbc.Driver</prop>
<prop key="org.quartz.dataSource.marsDS.URL">{server_url}</prop>
<prop key="org.quartz.dataSource.marsDS.user">{user_name}</prop>
<prop key="org.quartz.dataSource.marsDS.password">{password}</prop>
<prop key="org.quartz.dataSource.marsDS.maxConnections">10</prop>
<prop key="org.quartz.dataSource.marsDS.validationQuery">select 1</prop>
<prop key="org.quartz.plugin.shutdownHook.class">org.quartz.plugins.management.ShutdownHookPlugin</prop>
<prop key="org.quartz.plugin.shutdownHook.cleanShutdown">false</prop>
</props>
</property>
<property name="taskExecutor" ref="myTaskExecutor" />
<property name="jobFactory">
<bean class="com.aexp.mars.job.MarsSpringBeanJobFactory"/>
</property>
</bean>
** Java类 - **
public class ExampleJob {
private static final Logger LOG = LoggerFactory.getLogger(ExampleJob.class);
protected void executeInternal(JobExecutionContext ctx) throws JobExecutionException {
System.out.println("Job is running");
LOG.info("Job ran");
}
public void execute(JobExecutionContext ctx) throws JobExecutionException {
System.out.println("Job#1 is running");
LOG.info("Job ran");
}
}
答案 0 :(得分:1)
得到了这个场景。我改变了cron表达式的值,每1分钟运行一次,但它仍然设置为我之前的值(即凌晨3点)。我添加了下面的属性,然后新的cron表达式开始工作..
<property name="overwriteExistingJobs" value="true"/>