ScheduleConfig.java 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package com.ruoyi.framework.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. */
  13. @Configuration
  14. public class ScheduleConfig
  15. {
  16. @Bean
  17. public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource)
  18. {
  19. SchedulerFactoryBean factory = new SchedulerFactoryBean();
  20. factory.setDataSource(dataSource);
  21. // quartz参数
  22. Properties prop = new Properties();
  23. prop.put("org.quartz.scheduler.instanceName", "RuoyiScheduler");
  24. prop.put("org.quartz.scheduler.instanceId", "AUTO");
  25. // 线程池配置
  26. prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
  27. prop.put("org.quartz.threadPool.threadCount", "20");
  28. prop.put("org.quartz.threadPool.threadPriority", "5");
  29. // JobStore配置
  30. prop.put("org.quartz.jobStore.class", "org.quartz.impl.jdbcjobstore.JobStoreTX");
  31. // 集群配置
  32. prop.put("org.quartz.jobStore.isClustered", "true");
  33. prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000");
  34. prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1");
  35. prop.put("org.quartz.jobStore.misfireThreshold", "12000");
  36. prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_");
  37. factory.setQuartzProperties(prop);
  38. factory.setSchedulerName("RuoyiScheduler");
  39. // 延时启动
  40. factory.setStartupDelay(1);
  41. factory.setApplicationContextSchedulerContextKey("applicationContextKey");
  42. // 可选,QuartzScheduler
  43. // 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了
  44. factory.setOverwriteExistingJobs(true);
  45. // 设置自动启动,默认为true
  46. factory.setAutoStartup(true);
  47. return factory;
  48. }
  49. }