ScheduleConfig.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * Copyright (c) 2016-2019 人人开源 All rights reserved.
  3. *
  4. * https://www.renren.io
  5. *
  6. * 版权所有,侵权必究!
  7. */
  8. package io.renren.modules.job.config;
  9. import org.springframework.context.annotation.Bean;
  10. import org.springframework.context.annotation.Configuration;
  11. import org.springframework.scheduling.quartz.SchedulerFactoryBean;
  12. import javax.sql.DataSource;
  13. import java.util.Properties;
  14. /**
  15. * 定时任务配置
  16. *
  17. * @author Mark sunlightcs@gmail.com
  18. */
  19. @Configuration
  20. public class ScheduleConfig {
  21. @Bean
  22. public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) {
  23. SchedulerFactoryBean factory = new SchedulerFactoryBean();
  24. factory.setDataSource(dataSource);
  25. //quartz参数
  26. Properties prop = new Properties();
  27. prop.put("org.quartz.scheduler.instanceName", "RenrenScheduler");
  28. prop.put("org.quartz.scheduler.instanceId", "AUTO");
  29. //线程池配置
  30. prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
  31. prop.put("org.quartz.threadPool.threadCount", "20");
  32. prop.put("org.quartz.threadPool.threadPriority", "5");
  33. //JobStore配置
  34. prop.put("org.quartz.jobStore.class", "org.quartz.impl.jdbcjobstore.JobStoreTX");
  35. //集群配置
  36. prop.put("org.quartz.jobStore.isClustered", "true");
  37. prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000");
  38. prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1");
  39. prop.put("org.quartz.jobStore.misfireThreshold", "12000");
  40. prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_");
  41. prop.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?");
  42. //PostgreSQL数据库,需要打开此注释
  43. //prop.put("org.quartz.jobStore.driverDelegateClass", "org.quartz.impl.jdbcjobstore.PostgreSQLDelegate");
  44. factory.setQuartzProperties(prop);
  45. factory.setSchedulerName("RenrenScheduler");
  46. //延时启动
  47. factory.setStartupDelay(30);
  48. factory.setApplicationContextSchedulerContextKey("applicationContextKey");
  49. //可选,QuartzScheduler 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了
  50. factory.setOverwriteExistingJobs(true);
  51. //设置自动启动,默认为true
  52. factory.setAutoStartup(true);
  53. return factory;
  54. }
  55. }