zoukankan      html  css  js  c++  java
  • Quartz Trigger Priority 触发器优先级

    Quartz Trigger Priority 触发器优先级

    当多个触发器在一个相同的时间内触发,并且调度引擎中的资源有限的情况下,那么具有较高优先级的触发器先触发。

    需要将配置文件中的org.quartz.threadPool.threadCount = 1设置为1,这样能更好的测试出效果。

    package com.gary.operation.jobdemo.example14;
    
    import static org.quartz.DateBuilder.futureDate;
    import static org.quartz.JobBuilder.newJob;
    import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
    import static org.quartz.TriggerBuilder.newTrigger;
    
    import java.util.Date;
    
    import org.quartz.JobDetail;
    import org.quartz.Scheduler;
    import org.quartz.SchedulerFactory;
    import org.quartz.Trigger;
    import org.quartz.DateBuilder.IntervalUnit;
    import org.quartz.impl.StdSchedulerFactory;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    public class PriorityExample {
        
        public void run() throws Exception {
            Logger log = LoggerFactory.getLogger(PriorityExample.class);
    
            // First we must get a reference to a scheduler
            SchedulerFactory sf = new StdSchedulerFactory();
            Scheduler sched = sf.getScheduler();
    
            JobDetail job = newJob(TriggerEchoJob.class)
                .withIdentity("TriggerEchoJob")
                .build();
                
            Date startTime = futureDate(5, IntervalUnit.SECOND);
            
            Trigger trigger1 = newTrigger()
                .withIdentity("Priority7 Trigger5SecondRepeat")
                .startAt(startTime)
                .withSchedule(simpleSchedule().withRepeatCount(1).withIntervalInSeconds(5))
                .withPriority(7)
                .forJob(job)
                .build();
    
            Trigger trigger2 = newTrigger()
                .withIdentity("Priority5 Trigger10SecondRepeat")
                .startAt(startTime)
                .withPriority(5)
                .withSchedule(simpleSchedule().withRepeatCount(1).withIntervalInSeconds(5))
                .forJob(job)
                .build();
            
            Trigger trigger3 = newTrigger()
                .withIdentity("Priority10 Trigger15SecondRepeat")
                .startAt(startTime)
                .withSchedule(simpleSchedule().withRepeatCount(1).withIntervalInSeconds(5))
                .withPriority(10)
                .forJob(job)
                .build();
    
            // Tell quartz to schedule the job using our trigger
            sched.scheduleJob(job, trigger1);
            sched.scheduleJob(trigger2);
            sched.scheduleJob(trigger3);
    
            sched.start();
    
            log.info("------- Waiting 30 seconds... -------------");
            try {
                Thread.sleep(30L * 1000L); 
                // executing...
            } catch (Exception e) {
            }
    
            sched.shutdown(true);
        }
    
        public static void main(String[] args) throws Exception {
            PriorityExample example = new PriorityExample();
            example.run();
        }
    }
  • 相关阅读:
    n8n 基于node 的流程自动化工具
    kubectl-trace 基于bpftrace 的kubernetes 集群性能分析工具
    bcc 基于bpf 分析linux 系统性能的强大工具包
    使用arthas 生成火焰图分析jvm
    openjdk11 stretch基础镜像无法找到对应openjdk dbg 包的问题
    async-profiler 容器使用常见问题
    使用jattach 在host 节点查看容器jvm信息
    使用async-profiler简单分析zeebe 工作流引擎的性能
    minio select api 试用
    使用zeebe DebugHttpExporter 查看zeebe 工作流信息
  • 原文地址:https://www.cnblogs.com/daxin/p/3927432.html
Copyright © 2011-2022 走看看