49 lines
1.7 KiB
Java
Raw Normal View History

2020-07-19 10:25:40 +08:00
package com.ruoyi.quartz.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
2021-02-13 21:13:09 +08:00
2020-07-19 10:25:40 +08:00
import javax.sql.DataSource;
import java.util.Properties;
/**
* 定时任务配置
2021-02-13 21:13:09 +08:00
*
2020-07-19 10:25:40 +08:00
* @author ruoyi
*/
@Configuration
2021-02-13 21:13:09 +08:00
public class ScheduleConfig {
2021-02-14 11:03:13 +08:00
2020-07-19 10:25:40 +08:00
@Bean
2021-02-13 21:13:09 +08:00
public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) {
2020-07-19 10:25:40 +08:00
SchedulerFactoryBean factory = new SchedulerFactoryBean();
factory.setDataSource(dataSource);
// quartz参数
Properties prop = new Properties();
prop.put("org.quartz.scheduler.instanceName", "RuoyiScheduler");
prop.put("org.quartz.scheduler.instanceId", "AUTO");
// 集群配置
prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000");
prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1");
prop.put("org.quartz.jobStore.txIsolationLevelSerializable", "true");
// sqlserver 启用
// prop.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?");
prop.put("org.quartz.jobStore.misfireThreshold", "12000");
factory.setQuartzProperties(prop);
factory.setSchedulerName("RuoyiScheduler");
// 延时启动
factory.setStartupDelay(1);
factory.setApplicationContextSchedulerContextKey("applicationContextKey");
// 可选QuartzScheduler
// 启动时更新己存在的Job这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了
factory.setOverwriteExistingJobs(true);
2021-02-14 11:03:13 +08:00
2020-07-19 10:25:40 +08:00
return factory;
}
}