参考
安装
- 说明
- 其是任务调度框架
- 基于Maven
- Quartz2
- 安装
- 安装包pom
<dependencies> <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz</artifactId> <version>2.2.1</version> </dependency> </dependencies>
- quartz.properties
- 路径
src/main/resources - 内容
org.quartz.scheduler.instanceName = MyScheduler org.quartz.threadPool.threadCount = 3 org.quartz.jobStore.class =org.quartz.simpl.RAMJobStore
- 路径
- 建立Job(测试Job)
package com.mingwang.simpleapp; import org.quartz.Job; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; public class HelloJob implements Job { public void execute(JobExecutionContext context) throws JobExecutionException { System.out.println("Hello Quartz!"); } }
- 运行
package com.mingwang.simpleapp; import org.quartz.*; import org.quartz.impl.StdSchedulerFactory; /** * Created by mingwang on 2017/10/28. */ public class Test { public static void main(String [] args) { quartz(); } public static void quartz() { JobDetail job = JobBuilder.newJob(HelloJob.class) .withIdentity("dummyJobName", "group1").build(); // Trigger the job to run on the next round minute Trigger trigger = TriggerBuilder .newTrigger() .withIdentity("dummyTriggerName", "group1") .withSchedule( SimpleScheduleBuilder.simpleSchedule() .withIntervalInSeconds(5).repeatForever()) .build(); // schedule it Scheduler scheduler = null; try { scheduler = new StdSchedulerFactory().getScheduler(); scheduler.start(); scheduler.scheduleJob(job, trigger); } catch (Exception e) { } } }
- 安装包pom
网友评论