zoukankan      html  css  js  c++  java
  • quartz延迟执行一次

    package com.example.balabala;
    
    import org.quartz.*;
    import org.quartz.impl.StdSchedulerFactory;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    import static org.quartz.JobBuilder.newJob;
    import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
    import static org.quartz.TriggerBuilder.newTrigger;
    
    @SpringBootApplication
    public class LibeiApplication {
    
        public static void main(String[] args) throws Exception {
            SpringApplication.run(LibeiApplication.class, args);
    
            Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
    
            JobDetail job = newJob(LibeiApplication.TestJob.class)
                    .withIdentity("cronJob", "testJob")
                    .build();
    
            String startDateStr = "2019-04-08 10:11:00";
            String endDateStr = "2019-04-10 15:35:00";
    
            Date startDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(startDateStr);
            Date endDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(endDateStr);
    
            Trigger cronTrigger = newTrigger()
                    .withIdentity("trigger1", "testJob")
                    .startAt(startDate)
    //                .withSchedule(CalendarIntervalScheduleBuilder.calendarIntervalSchedule().withIntervalInMinutes(1))
    //                .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInMinutes(1).withRepeatCount(2))
                    .endAt(endDate)
                    .build();
    
            scheduler.scheduleJob(job, cronTrigger);
            scheduler.start();
        }
    
        public static class TestJob implements Job {
            @Override
            public void execute(JobExecutionContext context) throws JobExecutionException {
                System.out.println("this is a cron scheduled test job");
                System.out.println(new Date());
            }
        }
    }
    

      

  • 相关阅读:
    measure time program
    Visual Studio Code 好用的 source code editor
    tmux
    singleTask, singleInstance使用心得
    IIS7中配置FastCGI运行PHP
    Node.js入门
    Excel的文件打开特别慢,xls文件特别大解决一例
    SQL Server开启READ_COMMITTED_SNAPSHOT
    [转]最全的常用正则表达式大全——包括校验数字、字符、一些特殊的需求等等本文出处
    “VS2013无法连接远程数据库”解决方案
  • 原文地址:https://www.cnblogs.com/shenwenkai/p/10674941.html
Copyright © 2011-2022 走看看