ScheduleConfig.java 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package com.ruoyi.quartz.config;
  2. import org.springframework.context.annotation.Bean;
  3. import org.springframework.context.annotation.Configuration;
  4. import org.springframework.scheduling.quartz.SchedulerFactoryBean;
  5. import javax.sql.DataSource;
  6. import java.util.Properties;
  7. /**
  8. * 定时任务配置
  9. *
  10. * @author ruoyi
  11. */
  12. @Configuration
  13. public class ScheduleConfig {
  14. @Bean
  15. public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) {
  16. SchedulerFactoryBean factory = new SchedulerFactoryBean();
  17. factory.setDataSource(dataSource);
  18. // quartz参数
  19. Properties prop = new Properties();
  20. prop.put("org.quartz.scheduler.instanceName", "RuoyiScheduler");
  21. prop.put("org.quartz.scheduler.instanceId", "AUTO");
  22. // 集群配置
  23. prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000");
  24. prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1");
  25. prop.put("org.quartz.jobStore.txIsolationLevelSerializable", "true");
  26. // sqlserver 启用
  27. // prop.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?");
  28. prop.put("org.quartz.jobStore.misfireThreshold", "12000");
  29. factory.setQuartzProperties(prop);
  30. factory.setSchedulerName("RuoyiScheduler");
  31. // 延时启动
  32. factory.setStartupDelay(1);
  33. factory.setApplicationContextSchedulerContextKey("applicationContextKey");
  34. // 可选,QuartzScheduler
  35. // 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了
  36. factory.setOverwriteExistingJobs(true);
  37. return factory;
  38. }
  39. }