File tree Expand file tree Collapse file tree
main/java/com/baeldung/java_quartz
test/java/com/baeldung/java_quartz Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <project xmlns =" http://maven.apache.org/POM/4.0.0" xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
2+ xsi:schemaLocation=" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
3+ <modelVersion >4.0.0</modelVersion >
4+
5+ <groupId >com.baeldung</groupId >
6+ <artifactId >java-quartz</artifactId >
7+ <version >0.0.1-SNAPSHOT</version >
8+ <packaging >jar</packaging >
9+
10+ <name >java-quartz</name >
11+ <url >http://maven.apache.org</url >
12+
13+ <properties >
14+ <project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
15+ </properties >
16+
17+ <dependencies >
18+ <dependency >
19+ <groupId >junit</groupId >
20+ <artifactId >junit</artifactId >
21+ <version >3.8.1</version >
22+ <scope >test</scope >
23+ </dependency >
24+ <dependency >
25+ <groupId >org.quartz-scheduler</groupId >
26+ <artifactId >quartz</artifactId >
27+ <version >2.3.0</version >
28+ </dependency >
29+
30+ </dependencies >
31+ </project >
Original file line number Diff line number Diff line change 1+ package com .baeldung .java_quartz ;
2+
3+ import org .quartz .JobBuilder ;
4+ import org .quartz .JobDetail ;
5+ import org .quartz .Scheduler ;
6+ import org .quartz .SchedulerException ;
7+ import org .quartz .SchedulerFactory ;
8+ import org .quartz .SimpleScheduleBuilder ;
9+ import org .quartz .Trigger ;
10+ import org .quartz .TriggerBuilder ;
11+ import org .quartz .impl .StdSchedulerFactory ;
12+
13+ public class QuartzExample {
14+
15+ public static void main (String args []) {
16+
17+ SchedulerFactory schedFact = new StdSchedulerFactory ();
18+ try {
19+
20+ Scheduler sched = schedFact .getScheduler ();
21+
22+ JobDetail job = JobBuilder .newJob (SimpleJob .class )
23+ .withIdentity ("myJob" , "group1" )
24+ .build ();
25+
26+ Trigger trigger = TriggerBuilder .newTrigger ()
27+ .withIdentity ("myTrigger" , "group1" )
28+ .startNow ()
29+ .withSchedule (SimpleScheduleBuilder .simpleSchedule ()
30+ .withIntervalInSeconds (40 )
31+ .repeatForever ())
32+ .build ();
33+
34+ sched .scheduleJob (job , trigger );
35+ sched .start ();
36+
37+ } catch (SchedulerException e ) {
38+ e .printStackTrace ();
39+ }
40+ }
41+
42+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .java_quartz ;
2+
3+ import org .quartz .Job ;
4+ import org .quartz .JobExecutionContext ;
5+ import org .quartz .JobExecutionException ;
6+
7+ public class SimpleJob implements Job {
8+
9+ public void execute (JobExecutionContext arg0 ) throws JobExecutionException {
10+ System .out .println ("This is a quartz job!" );
11+ }
12+
13+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .java_quartz ;
2+
3+ import junit .framework .Test ;
4+ import junit .framework .TestCase ;
5+ import junit .framework .TestSuite ;
6+
7+ /**
8+ * Unit test for simple App.
9+ */
10+ public class AppTest
11+ extends TestCase
12+ {
13+ /**
14+ * Create the test case
15+ *
16+ * @param testName name of the test case
17+ */
18+ public AppTest ( String testName )
19+ {
20+ super ( testName );
21+ }
22+
23+ /**
24+ * @return the suite of tests being tested
25+ */
26+ public static Test suite ()
27+ {
28+ return new TestSuite ( AppTest .class );
29+ }
30+
31+ /**
32+ * Rigourous Test :-)
33+ */
34+ public void testApp ()
35+ {
36+ assertTrue ( true );
37+ }
38+ }
You can’t perform that action at this time.
0 commit comments