沙钢智慧能源系统后端代码
liriming
2024-10-14 ccf75464534965c47866449b2b4e457a6dadede9
提交 | 用户 | 时间
516ef4 1 package com.iailab.module.shasteel.job.config;
L 2
3 import org.springframework.context.annotation.Bean;
4 import org.springframework.context.annotation.Configuration;
5 import org.springframework.scheduling.quartz.SchedulerFactoryBean;
6
7 import javax.sql.DataSource;
8 import java.util.Properties;
9
10 /**
11  * 定时任务配置
12  *
13  * @author Mark sunlightcs@gmail.com
14  */
15 @Configuration
16 public class ScheduleConfig {
17
18     @Bean
19     public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) {
20         SchedulerFactoryBean factory = new SchedulerFactoryBean();
21         factory.setDataSource(dataSource);
22
23         //quartz参数
24         Properties prop = new Properties();
25         prop.put("org.quartz.scheduler.instanceName", "IailabDataScheduler");
26         prop.put("org.quartz.scheduler.instanceId", "AUTO");
27         //线程池配置
28         prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
29         prop.put("org.quartz.threadPool.threadCount", "20");
30         prop.put("org.quartz.threadPool.threadPriority", "5");
31         //JobStore配置
32         prop.put("org.quartz.jobStore.class", "org.springframework.scheduling.quartz.LocalDataSourceJobStore");
33         //集群配置
34         prop.put("org.quartz.jobStore.isClustered", "true");
35         prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000");
36         prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1");
37
38         prop.put("org.quartz.jobStore.misfireThreshold", "12000");
39         prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_");
40         prop.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?");
41
42         //PostgreSQL数据库,需要打开此注释
43         //prop.put("org.quartz.jobStore.driverDelegateClass", "org.quartz.impl.jdbcjobstore.PostgreSQLDelegate");
44
45         factory.setQuartzProperties(prop);
46
47         factory.setSchedulerName("IailabDataScheduler");
48         //延时启动
49         factory.setStartupDelay(30);
50         factory.setApplicationContextSchedulerContextKey("applicationContextKey");
51         //可选,QuartzScheduler 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了
52         factory.setOverwriteExistingJobs(true);
53         //设置自动启动,默认为true
54         factory.setAutoStartup(true);
55
56         return factory;
57     }
58 }