quartz入门

public static void main(String[] args) {
//配置模式 build模式
//1.实例一个JOB
JobDetail jobDetail = JobBuilder.newJob(QuartzJob.class)
.withIdentity("myjob", "group")
//jobDataMap 在构建JobDetail时,可以将数据放入JobDataMap,
.usingJobData("jobSays", "Hello World!")
.usingJobData("myFloatValue", 3.14f)
.build();
System.out.println("任务名:"+jobDetail.getKey().getName());
System.out.println("任务组:"+jobDetail.getKey().getGroup());
System.out.println("任务类名:"+jobDetail.getJobClass().getName());
//2.0实例一个触发器
Trigger trigger = newTrigger()
.withIdentity("trigger1", "group1")
.startNow()
.withSchedule(simpleSchedule()//simple方式配置 corn配置请自行百度
.withIntervalInSeconds(4)
.repeatForever())
.build();
//3.0调度器调度实例化,整合实例的job和触发器
try {
Scheduler scheduler =StdSchedulerFactory.getDefaultScheduler();
scheduler.scheduleJob(jobDetail, trigger);
//4.启动
scheduler.start();
} catch (SchedulerException e) {
e.printStackTrace();
}
}

你可能感兴趣的:(quartz入门)