概述
package com.julongtech.main;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
/**
* 定时任务测试
* @author julong
* @date 2017-1-20 下午02:56:12
*/
public class TestJob implements Job {
//执行方法
public void execute(JobExecutionContext arg0) throws JobExecutionException {
// TODO Auto-generated method stub
System.out.println("123");
}
}
package com.julongtech.main;import org.quartz.JobBuilder;import org.quartz.JobDetail;import org.quartz.Scheduler;import org.quartz.SchedulerException;import org.quartz.SimpleScheduleBuilder;import org.quartz.Trigger;import org.quartz.TriggerBuilder;import org.quartz.impl.StdSchedulerFactory;public class Test {/** * @param args * @author julong * @throws SchedulerException * @date 2017-1-20 下午03:01:37 */public static void main(String[] args) throws SchedulerException {// TODO Auto-generated method stub//JobDetail jobDetail = JobBuilder.newJob(TestJob.class).withIdentity("testJob","group1").build();Trigger trigger = TriggerBuilder//.newTrigger()//.withIdentity("dummyTriggerName", "group1")//.withSchedule(//SimpleScheduleBuilder.simpleSchedule()//.withIntervalInSeconds(5).repeatForever())//.build();Scheduler scheduler = new StdSchedulerFactory().getScheduler();//scheduler.start();//scheduler.scheduleJob(jobDetail, trigger);//定义定工作创建对象JobBuilder jobBuilder = JobBuilder.newJob(TestJob.class).withIdentity("JOB1", "JULONG");//为定时器定义编号 和分组JobDetail jobDetail = jobBuilder.build();//创建任务触发器TriggerBuilder trigger = TriggerBuilder.newTrigger();SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule();scheduleBuilder.withIntervalInSeconds(1);//每一秒执行一次scheduleBuilder.repeatForever();//永远重复执行trigger.withSchedule(scheduleBuilder);//定义触发器Trigger trigger2 = trigger.build();//创建任务调度对象Scheduler scheduler = new StdSchedulerFactory().getScheduler();scheduler.scheduleJob(jobDetail, trigger2);scheduler.start();//启动}} 所需的jar quartz-2.2.1.jar c3p0-0.9.1.1.jar slf4j-api-1.6.6.jar
最后
以上就是成就身影为你收集整理的java quartz如何使用,java 中的 quartz使用的全部内容,希望文章能够帮你解决java quartz如何使用,java 中的 quartz使用所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复