メモ。基本QUARTZ QUICK STARTを見てやっただけ。
1.quartzのダウンロード
quartz
2.ダウンロードしたファイルを解凍してlibにquartz-2.1.6.jarをぶっこむ
3.quartz.propertiesを作成する。
(WEB-INF/classes以下のどっかに配備されるようにしとく)
内容は
HelloJob.java
QuartzTest.javaの実行結果
1.quartzのダウンロード
quartz
2.ダウンロードしたファイルを解凍してlibにquartz-2.1.6.jarをぶっこむ
3.quartz.propertiesを作成する。
(WEB-INF/classes以下のどっかに配備されるようにしとく)
内容は
org.quartz.scheduler.instanceName = MyScheduler
org.quartz.threadPool.threadCount = 3
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
4.Javaから呼び出してみる
QuartzTest.java
// Trigger the job to run now, and then repeat every 40 seconds
4.Javaから呼び出してみる
QuartzTest.java
package hoge.scheduler;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
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 QuartzTest {
/**
* @param args
*/
public static void main(String[] args) {
try {
// Grab the Scheduler instance from the Factory
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
// and start it off
scheduler.start();
System.out.println("START");
// define the job and tie it to our HelloJob class
JobDetail job = newJob(HelloJob.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(10)
.repeatForever())
.build();
// Tell quartz to schedule the job using our trigger
scheduler.scheduleJob(job, trigger);
Thread.sleep(11000);
scheduler.shutdown();
System.out.println("END");
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
package hoge.scheduler;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
public class HelloJob implements Job {
@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
System.out.println("HOGE");
}
}
QuartzTest.javaの実行結果
START
HOGE
HOGE
END