Spring-quartz问题记录

https://www.jianshu.com/p/572322b36383 一篇不错的帖子
1:定时任务传递参数

JobDataMap jobDataMap = new JobDataMap();
// 设置参数
jobDataMap.put("executeTime", scheduleInfo.getExecuteTime());
scheduler.triggerJob(JobKey.jobKey(jobName, jobGroup), jobDataMap);

接收:

 @Override
    public void execute(JobExecutionContext context) {
        JobDataMap dataMap = context.getMergedJobDataMap();
        String executeTime = dataMap.getString("executeTime");
    }

注意错误写法:
下面这种写法会将参数持久化到数据库中

JobDetail job = JobBuilder.newJob(DailyReportJob.class)
                        .withIdentity(jobName, jobGroup)
                        .storeDurably(true)
                        .build();
// 设置参数
job.getJobDataMap().put("executeTime", scheduleInfo.getExecuteTime());
scheduler.addJob(job, true);
scheduler.triggerJob(JobKey.jobKey(jobName, jobGroup));

2:定时任务大姨妈问题
问题描述:冒烟环境经常会发生定时任务每隔几天就有几小时不执行的情况
经过排查,发现日志报了misfired问题,最后通过修改参数解决了问题
misfireThreshold: 120000
threadCount: 15

spring:
  quartz:
    properties:
      org:
        quartz:
          scheduler:
            instanceName: clusteredScheduler
            instanceId: AUTO
          jobStore:
            class: org.quartz.impl.jdbcjobstore.JobStoreTX
            driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate
            tablePrefix: QRTZ_
            isClustered: true
            clusterCheckinInterval: 10000
            useProperties: false
            dataSource: qzDS
            misfireThreshold: 120000
          threadPool:
            class: org.quartz.simpl.SimpleThreadPool
            threadCount: 15
            threadPriority: 5
            threadsInheritContextClassLoaderOfInitializingThread: true
          #数据库方式
          job-store-type: jdbc
          #初始化表结构
          jdbc:
            initialize-schema: never
          dataSource:
            qzDS:
              driver: com.mysql.jdbc.Driver
              URL: jdbc:mysql://xxxx:3306/xxx_quartz?characterEncoding=UTF-8
              user: '{cipher}'
              password: '{cipher}'
              maxConnections: 10
              provider: hikaricp
  datasource:
    url: jdbc:mysql://xxxx:3306/xxx?allowMultiQueries=true
  kafka:
    producer:
      properties:
        security:
          protocol: SASL_PLAINTEXT
        sasl:
          mechanism: PLAIN

3:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值