zoukankan      html  css  js  c++  java
  • 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();
    		
    	}
    

      

    发现这个使用simpleTrigger 的没有参数设置第一次启动时不执行 ....只有CromTrigger 有个参数可以设置第一次添加不执行计划 “withMisfireHandlingInstructionDoNothing()”

    转载请注时出处:http://www.cnblogs.com/jackicalSong/

    所以我的第一个方法就废了,但第二个方法一样可以用.....

  • 相关阅读:
    哈希表
    跳表
    哈夫曼之谜
    选择树、判定树和查找树

    将gbk字符串转换成utf-8,存储到注册表中后,再次从注册表读取转换成gbk,有问题!!!
    函数内部还是不要使用 strtok()
    没想到: System.out.println(n1 == f1 ? n1 : f1);
    在不同DPI屏幕环境下,让图标显示的尺寸保持不变,使用 LoadImage() 加载图标
    在多线程中显示模态窗口,出现异常现象
  • 原文地址:https://www.cnblogs.com/jackicalSong/p/3922067.html
Copyright © 2011-2022 走看看