我是靠谱客的博主 敏感小蘑菇,最近开发中收集的这篇文章主要介绍Quartz,启动不立即执行问题,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Quartz,启动不立即执行问题

我的Quartz 是2.2版本,

在java程序中写了两个加入计划方法


  添加简单计划任务 author:iresearch.com.cn -- jackical
     public static void AddSimplejob(String jobName,String strTrigger, int id, int hour, int minute,Date DateStart) throws SchedulerException{
         
         Scheduler sched=sf.getScheduler();
         
         Calendar calendar=GregorianCalendar.getInstance();
         calendar.setTime(DateStart);
         int intYear= calendar.get(Calendar.YEAR);
         int intMonth=calendar.get(Calendar.MONTH)+ 1 ;
         int intDay=calendar.get(Calendar.DAY_OF_MONTH);
         
         Date runDate=DateBuilder.dateOf(hour, minute, 0 ,intDay,intMonth,intYear);   //  设置执行的时间
         
         JobDetail jobDetail=JobBuilder.newJob(DoJob. class )
                 .withIdentity(jobName,JOB_GROUP_NAME)
                 .usingJobData( "id" ,id)
                 .build();
         
         SimpleTrigger trigger=(SimpleTrigger)TriggerBuilder
                 .newTrigger()
                 .withIdentity(strTrigger,TRIGGER_GROUP_NAME)
                 .startAt(runDate)
                 .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                         .withIntervalInMinutes( 3 )
                         .withRepeatCount( 0 )
                         )
                 .build();
         
         /*
          *              .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                         .withIntervalInSeconds(10)
                         .withRepeatCount(0)
                         )
          * */
         
         sched.scheduleJob(jobDetail,trigger);
         sched.start();
     }
     
     /  添加定时任务 author:iresearch.com.cn -- jackical
     public static void AddCronJob(String jobName,String strTrigger, int id,String strExp,Date DateStart,Date DateEnd) throws SchedulerException, ParseException{
         
         Scheduler sched=sf.getScheduler();
         
         JobDetail jobDetail=JobBuilder.newJob(DoJob. class )
                 .withIdentity(jobName,JOB_GROUP_NAME)
                 .usingJobData( "id" ,id)
                 .build();
         
         Trigger trigger=(CronTrigger)TriggerBuilder
                 .newTrigger()
                 .withIdentity(strTrigger,TRIGGER_GROUP_NAME)
                 .startAt(DateStart)
                 .endAt(DateEnd)
                 .withSchedule(CronScheduleBuilder.cronSchedule(strExp)
                         .withMisfireHandlingInstructionDoNothing()
                         )
                 .build();
         
         
         sched.scheduleJob(jobDetail,trigger);
         sched.start();
         
     }

最后

以上就是敏感小蘑菇为你收集整理的Quartz,启动不立即执行问题的全部内容,希望文章能够帮你解决Quartz,启动不立即执行问题所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(47)

评论列表共有 0 条评论

立即
投稿
返回
顶部