Created
August 21, 2013 15:37
-
-
Save wendal/6296043 to your computer and use it in GitHub Desktop.
演示通过nutz的@SetupBy启动quartz
This file contains hidden or 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 net.wendal.quartz; | |
import org.quartz.Job; | |
import org.quartz.JobExecutionContext; | |
import org.quartz.JobExecutionException; | |
public class FuckJob implements Job { | |
@Override | |
public void execute(JobExecutionContext arg0) throws JobExecutionException { | |
System.out.println("Hi, I am here"); | |
} | |
} |
This file contains hidden or 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
@SetupBy(QuartzSetup.class) | |
public class MainModule {} |
This file contains hidden or 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
org.quartz.scheduler.instanceName = NutzScheduler | |
org.quartz.threadPool.threadCount = 3 | |
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore |
This file contains hidden or 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 net.wendal.quartz; | |
import org.nutz.mvc.NutConfig; | |
import org.nutz.mvc.Setup; | |
import org.quartz.JobDetail; | |
import org.quartz.Scheduler; | |
import org.quartz.SchedulerException; | |
import org.quartz.Trigger; | |
import org.quartz.impl.StdSchedulerFactory; | |
import static org.quartz.JobBuilder.*; | |
import static org.quartz.TriggerBuilder.*; | |
import static org.quartz.SimpleScheduleBuilder.*; | |
public class QuartzSetup implements Setup { | |
Scheduler scheduler; | |
public void init(NutConfig nc) { | |
try { | |
scheduler = StdSchedulerFactory.getDefaultScheduler(); | |
// and start it off | |
scheduler.start(); | |
JobDetail job = newJob(FuckJob.class).withIdentity("job1", "group1").build(); | |
// Trigger the job to run now, and then repeat every 40 seconds | |
Trigger trigger = newTrigger() | |
.withIdentity("trigger1", "group1") | |
.startNow() | |
.withSchedule( | |
simpleSchedule().withIntervalInSeconds(5) | |
.repeatForever()).build(); | |
// Tell quartz to schedule the job using our trigger | |
scheduler.scheduleJob(job, trigger); | |
} catch (SchedulerException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
@Override | |
public void destroy(NutConfig nc) { | |
if (scheduler != null) | |
try { | |
scheduler.shutdown(); | |
} catch (SchedulerException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
// public static void main(String[] args) { | |
// new QuartzSetup().init(null); | |
// } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment