From b65e33c1e005ac5a4dbaad8a97e9b0abe808559d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E6=B2=90?= Date: Sat, 3 Sep 2022 23:11:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E9=9B=86=E7=BE=A4=E9=83=A8=E7=BD=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/maku/quartz/config/ScheduleConfig.java | 52 ++++++++++++++++++++++ .../net/maku/quartz/entity/ScheduleJobEntity.java | 6 ++- 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/config/ScheduleConfig.java diff --git a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/config/ScheduleConfig.java b/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/config/ScheduleConfig.java new file mode 100644 index 0000000..7598e0b --- /dev/null +++ b/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/config/ScheduleConfig.java @@ -0,0 +1,52 @@ +package net.maku.quartz.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.quartz.SchedulerFactoryBean; + +import javax.sql.DataSource; +import java.util.Properties; + +/** + * 定时任务配置 + * + * @author 阿沐 babamu@126.com + */ +@Configuration +public class ScheduleConfig { + + @Bean + public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) { + // quartz参数 + Properties prop = new Properties(); + prop.put("org.quartz.scheduler.instanceName", "MakuScheduler"); + prop.put("org.quartz.scheduler.instanceId", "AUTO"); + // 线程池配置 + prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool"); + prop.put("org.quartz.threadPool.threadCount", "20"); + prop.put("org.quartz.threadPool.threadPriority", "5"); + // jobStore配置 + prop.put("org.quartz.jobStore.class", "org.springframework.scheduling.quartz.LocalDataSourceJobStore"); + // 集群配置 + prop.put("org.quartz.jobStore.isClustered", "true"); + prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000"); + prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1"); + prop.put("org.quartz.jobStore.txIsolationLevelSerializable", "true"); + + prop.put("org.quartz.jobStore.misfireThreshold", "12000"); + prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_"); + prop.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?"); + + SchedulerFactoryBean factory = new SchedulerFactoryBean(); + factory.setSchedulerName("MakuScheduler"); + factory.setDataSource(dataSource); + factory.setQuartzProperties(prop); + // 延时启动 + factory.setStartupDelay(10); + factory.setApplicationContextSchedulerContextKey("applicationContextKey"); + // 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了 + factory.setOverwriteExistingJobs(true); + + return factory; + } +} diff --git a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/entity/ScheduleJobEntity.java b/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/entity/ScheduleJobEntity.java index 8a0d91f..9bc40c3 100644 --- a/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/entity/ScheduleJobEntity.java +++ b/maku-boot-module/maku-boot-quartz/src/main/java/net/maku/quartz/entity/ScheduleJobEntity.java @@ -5,6 +5,8 @@ import lombok.Data; import lombok.EqualsAndHashCode; import net.maku.framework.common.entity.BaseEntity; +import java.io.Serializable; + /** * 定时任务 * @@ -13,7 +15,9 @@ import net.maku.framework.common.entity.BaseEntity; @Data @EqualsAndHashCode(callSuper=false) @TableName("schedule_job") -public class ScheduleJobEntity extends BaseEntity { +public class ScheduleJobEntity extends BaseEntity implements Serializable { + private static final long serialVersionUID = 1L; + /** * 任务名称 */