Adding more examples to the Quartz project (#2101)
This commit is contained in:
parent
eba5b938f5
commit
fada609f16
|
@ -0,0 +1,13 @@
|
|||
package com.baeldung.quartz;
|
||||
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
|
||||
public class JobA implements Job {
|
||||
|
||||
public void execute(JobExecutionContext arg0) throws JobExecutionException {
|
||||
System.out.println("This is the job A");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.baeldung.quartz;
|
||||
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
|
||||
public class JobB implements Job {
|
||||
|
||||
public void execute(JobExecutionContext arg0) throws JobExecutionException {
|
||||
System.out.println("This is the job B");
|
||||
}
|
||||
|
||||
}
|
|
@ -21,6 +21,8 @@ public class QuartzExample {
|
|||
|
||||
JobDetail job = JobBuilder.newJob(SimpleJob.class)
|
||||
.withIdentity("myJob", "group1")
|
||||
.usingJobData("jobSays", "Hello World!")
|
||||
.usingJobData("myFloatValue", 3.141f)
|
||||
.build();
|
||||
|
||||
Trigger trigger = TriggerBuilder.newTrigger()
|
||||
|
@ -30,8 +32,36 @@ public class QuartzExample {
|
|||
.withIntervalInSeconds(40)
|
||||
.repeatForever())
|
||||
.build();
|
||||
|
||||
JobDetail jobA = JobBuilder.newJob(JobA.class)
|
||||
.withIdentity("jobA", "group2")
|
||||
.build();
|
||||
|
||||
JobDetail jobB = JobBuilder.newJob(JobB.class)
|
||||
.withIdentity("jobB", "group2")
|
||||
.build();
|
||||
|
||||
Trigger triggerA = TriggerBuilder.newTrigger()
|
||||
.withIdentity("triggerA", "group2")
|
||||
.startNow()
|
||||
.withPriority(15)
|
||||
.withSchedule(SimpleScheduleBuilder.simpleSchedule()
|
||||
.withIntervalInSeconds(40)
|
||||
.repeatForever())
|
||||
.build();
|
||||
|
||||
Trigger triggerB = TriggerBuilder.newTrigger()
|
||||
.withIdentity("triggerB", "group2")
|
||||
.startNow()
|
||||
.withPriority(10)
|
||||
.withSchedule(SimpleScheduleBuilder.simpleSchedule()
|
||||
.withIntervalInSeconds(20)
|
||||
.repeatForever())
|
||||
.build();
|
||||
|
||||
sched.scheduleJob(job, trigger);
|
||||
sched.scheduleJob(jobA, triggerA);
|
||||
sched.scheduleJob(jobB, triggerB);
|
||||
sched.start();
|
||||
|
||||
} catch (SchedulerException e) {
|
||||
|
|
|
@ -1,13 +1,21 @@
|
|||
package com.baeldung.quartz;
|
||||
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobDataMap;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
|
||||
public class SimpleJob implements Job {
|
||||
|
||||
public void execute(JobExecutionContext arg0) throws JobExecutionException {
|
||||
System.out.println("This is a quartz job!");
|
||||
public void execute(JobExecutionContext context) throws JobExecutionException {
|
||||
JobDataMap dataMap = context.getJobDetail()
|
||||
.getJobDataMap();
|
||||
|
||||
String jobSays = dataMap.getString("jobSays");
|
||||
float myFloatValue = dataMap.getFloat("myFloatValue");
|
||||
|
||||
System.out.println("Job says: " + jobSays + ", and val is: " + myFloatValue);
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue