1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
package org.knowm.sundial.jobs; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.knowm.sundial.Job; import org.knowm.sundial.annotations.CronTrigger; import org.knowm.sundial.exceptions.JobInterruptException; @CronTrigger(cron = "0/20 * * * * ?") public class SampleJob5 extends Job { private final Logger logger = LoggerFactory.getLogger(SampleJob5.class); @Override public void doRun() throws JobInterruptException { logger.info("Running SampleJob5."); // Do something interesting... } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
package org.knowm.sundial.jobs; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.knowm.sundial.Job; import org.knowm.sundial.annotations.SimpleTrigger; import org.knowm.sundial.exceptions.JobInterruptException; @SimpleTrigger(repeatInterval = 1000, repeatCount = 10) public class SampleJob6 extends Job { private final Logger logger = LoggerFactory.getLogger(SampleJob6.class); @Override public void doRun() throws JobInterruptException { logger.info("Running SampleJob6."); // Do something interesting... } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
<?xml version='1.0' encoding='utf-8'?> <job-scheduling-data> <schedule> <!-- job with cron trigger --> <job> <name>SampleJob3</name> <job-class>org.knowm.sundial.jobs.SampleJob3</job-class> <concurrency-allowed>true</concurrency-allowed> </job> <trigger> <cron> <name>SampleJob3-Trigger</name> <job-name>SampleJob3</job-name> <cron-expression>*/15 * * * * ?</cron-expression> </cron> </trigger> <!-- job with simple trigger --> <job> <name>SampleJob2</name> <job-class>org.knowm.sundial.jobs.SampleJob2</job-class> <job-data-map> <entry> <key>MyParam</key> <value>42</value> </entry> </job-data-map> </job> <trigger> <simple> <name>SampleJob2-Trigger</name> <job-name>SampleJob2</job-name> <repeat-count>5</repeat-count> <repeat-interval>5000</repeat-interval> </simple> </trigger> </schedule> </job-scheduling-data> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
package org.knowm.sundial.jobs; import java.util.concurrent.TimeUnit; /** * @author timmolter */ public class SampleRun { /** * Make sure jobs.xml is on the classpath! */ public static void main(String[] args) { SundialJobScheduler.startScheduler("org.knowm.sundial.jobs"); // package with annotated Jobs SundialJobScheduler.addJob("SampleJob1", "org.knowm.sundial.jobs.SampleJob1"); SundialJobScheduler.addCronTrigger("SampleJob1-Cron-Trigger", "SampleJob1", "0/10 * * * * ?"); SundialJobScheduler.addSimpleTrigger("SampleJob1-Simple-Trigger", "SampleJob1", -1, TimeUnit.SECONDS.toMillis(3)); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
package org.knowm.sundial.jobs; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.knowm.sundial.Job; import org.knowm.sundial.annotations.CronTrigger; import org.knowm.sundial.exceptions.JobInterruptException; @CronTrigger(cron = "0/5 * * * * ?", jobDataMap = { "KEY_1:VALUE_1", "KEY_2:1000" }) public class SampleJob4 extends Job { private final Logger logger = LoggerFactory.getLogger(SampleJob4.class); @Override public void doRun() throws JobInterruptException { logger.info("Running SampleJob4."); // Do something interesting... String value1 = getJobContext().get("KEY_1"); logger.info("value1 = " + value1); String value2AsString = getJobContext().get("KEY_2"); Integer valueAsInt = Integer.valueOf(value2AsString); logger.info("value2 = " + valueAsInt); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
package org.knowm.sundial.jobs; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.knowm.sundial.JobAction; /** * A sample Job Action that simply logs a message every time it's called. * * @author timmolter */ public class SampleJobAction extends JobAction { private final Logger logger = LoggerFactory.getLogger(SampleJobAction.class); @Override public void doRun() { Integer myValue = getJobContext().get("MyValue"); logger.info("myValue: " + myValue); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
package org.knowm.sundial.jobs; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.knowm.sundial.Job; import org.knowm.sundial.JobContext; import org.knowm.sundial.exceptions.JobInterruptException; public class SampleJob3 extends Job { private final Logger logger = LoggerFactory.getLogger(SampleJob3.class); @Override public void doRun() throws JobInterruptException { logger.info("Running SampleJob3."); JobContext context = getJobContext(); context.put("MyValue", new Integer(123)); new SampleJobAction().run(); } } |
1 2 3 4 5 6 7 8 9 |
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <listener> <listener-class>org.knowm.sundial.ee.SundialInitializerListener</listener-class> </listener> </web-app> |