Created
February 5, 2018 12:43
-
-
Save kh0ma/d578b439c73f4953ab581f7e7e391343 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.kh0ma.quarztest; | |
import org.quartz.Job; | |
import org.quartz.JobExecutionContext; | |
import org.quartz.JobExecutionException; | |
/** | |
* @author Olexander Khomenko | |
*/ | |
public class HelloJob implements Job | |
{ | |
public void execute(JobExecutionContext context) | |
throws JobExecutionException { | |
System.out.println("Hello Quartz!" + context.getJobDetail().getKey()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.kh0ma.quarztest; | |
import org.quartz.*; | |
import org.quartz.impl.StdSchedulerFactory; | |
/** | |
* @author Olexander Khomenko | |
* | |
*/ | |
public class Main { | |
public static void main(String[] args) throws SchedulerException { | |
// Quartz 1.6.3 | |
// JobDetail job = new JobDetail(); | |
// job.setName("dummyJobName"); | |
// job.setJobClass(HelloJob.class); | |
JobDetail job = JobBuilder.newJob(HelloJob.class) | |
.withIdentity("dummyJobName", "group1").build(); | |
JobDetail job2 = JobBuilder.newJob(HelloJob.class) | |
.withIdentity("dummyJobName2", "group2").build(); | |
//Quartz 1.6.3 | |
// SimpleTrigger trigger = new SimpleTrigger(); | |
// trigger.setStartTime(new Date(System.currentTimeMillis() + 1000)); | |
// trigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY); | |
// trigger.setRepeatInterval(30000); | |
// Trigger the job to run on the next round minute | |
Trigger trigger = TriggerBuilder | |
.newTrigger() | |
.withIdentity("dummyTriggerName", "group1") | |
.withSchedule( | |
SimpleScheduleBuilder.simpleSchedule() | |
.withIntervalInSeconds(5).repeatForever()) | |
.build(); | |
Trigger trigger2 = TriggerBuilder | |
.newTrigger() | |
.withIdentity("dummyTriggerName2", "group2") | |
.withSchedule( | |
SimpleScheduleBuilder.simpleSchedule() | |
.withIntervalInSeconds(5).repeatForever()) | |
.build(); | |
// schedule it | |
Scheduler scheduler = new StdSchedulerFactory().getScheduler(); | |
scheduler.start(); | |
scheduler.scheduleJob(job, trigger); | |
scheduler.scheduleJob(job2, trigger2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment