Skip to content

Commit fada609

Browse files
Alex Vargaszhendrikse
authored andcommitted
Adding more examples to the Quartz project (eugenp#2101)
1 parent eba5b93 commit fada609

4 files changed

Lines changed: 66 additions & 2 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.baeldung.quartz;
2+
3+
import org.quartz.Job;
4+
import org.quartz.JobExecutionContext;
5+
import org.quartz.JobExecutionException;
6+
7+
public class JobA implements Job {
8+
9+
public void execute(JobExecutionContext arg0) throws JobExecutionException {
10+
System.out.println("This is the job A");
11+
}
12+
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.baeldung.quartz;
2+
3+
import org.quartz.Job;
4+
import org.quartz.JobExecutionContext;
5+
import org.quartz.JobExecutionException;
6+
7+
public class JobB implements Job {
8+
9+
public void execute(JobExecutionContext arg0) throws JobExecutionException {
10+
System.out.println("This is the job B");
11+
}
12+
13+
}

‎libraries/src/main/java/com/baeldung/quartz/QuartzExample.java‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public static void main(String args[]) {
2121

2222
JobDetail job = JobBuilder.newJob(SimpleJob.class)
2323
.withIdentity("myJob", "group1")
24+
.usingJobData("jobSays", "Hello World!")
25+
.usingJobData("myFloatValue", 3.141f)
2426
.build();
2527

2628
Trigger trigger = TriggerBuilder.newTrigger()
@@ -30,8 +32,36 @@ public static void main(String args[]) {
3032
.withIntervalInSeconds(40)
3133
.repeatForever())
3234
.build();
35+
36+
JobDetail jobA = JobBuilder.newJob(JobA.class)
37+
.withIdentity("jobA", "group2")
38+
.build();
39+
40+
JobDetail jobB = JobBuilder.newJob(JobB.class)
41+
.withIdentity("jobB", "group2")
42+
.build();
43+
44+
Trigger triggerA = TriggerBuilder.newTrigger()
45+
.withIdentity("triggerA", "group2")
46+
.startNow()
47+
.withPriority(15)
48+
.withSchedule(SimpleScheduleBuilder.simpleSchedule()
49+
.withIntervalInSeconds(40)
50+
.repeatForever())
51+
.build();
52+
53+
Trigger triggerB = TriggerBuilder.newTrigger()
54+
.withIdentity("triggerB", "group2")
55+
.startNow()
56+
.withPriority(10)
57+
.withSchedule(SimpleScheduleBuilder.simpleSchedule()
58+
.withIntervalInSeconds(20)
59+
.repeatForever())
60+
.build();
3361

3462
sched.scheduleJob(job, trigger);
63+
sched.scheduleJob(jobA, triggerA);
64+
sched.scheduleJob(jobB, triggerB);
3565
sched.start();
3666

3767
} catch (SchedulerException e) {
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
package com.baeldung.quartz;
22

33
import org.quartz.Job;
4+
import org.quartz.JobDataMap;
45
import org.quartz.JobExecutionContext;
56
import org.quartz.JobExecutionException;
67

78
public class SimpleJob implements Job {
89

9-
public void execute(JobExecutionContext arg0) throws JobExecutionException {
10-
System.out.println("This is a quartz job!");
10+
public void execute(JobExecutionContext context) throws JobExecutionException {
11+
JobDataMap dataMap = context.getJobDetail()
12+
.getJobDataMap();
13+
14+
String jobSays = dataMap.getString("jobSays");
15+
float myFloatValue = dataMap.getFloat("myFloatValue");
16+
17+
System.out.println("Job says: " + jobSays + ", and val is: " + myFloatValue);
18+
1119
}
1220

1321
}

0 commit comments

Comments
 (0)