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/

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

 

你可能感兴趣的:(quartz)