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/

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

  • 相关阅读:
    Aurora 数据库支持多达五个跨区域只读副本
    Amazon RDS 的 Oracle 只读副本
    Amazon EC2 密钥对
    DynamoDB 读取请求单位和写入请求单位
    使用 EBS 优化的实例或 10 Gb 网络实例
    启动 LAMP 堆栈 Web 应用程序
    AWS 中的错误重试和指数退避 Error Retries and Exponential Backoff in AWS
    使用 Amazon S3 阻止公有访问
    路由表 Router Table
    使用MySQLAdmin工具查看QPS
  • 原文地址:https://www.cnblogs.com/jackicalSong/p/3922067.html
Copyright © 2011-2022 走看看