Create job for application java
package java.job;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
public class testjob implements Job
{
@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
try {
testSchedule();
} catch (Exception e) {
System.out.println("execute error: " + e.toString());
}
}
private void testSchedule()
{
System.out.println("test schedule =============================");
}
}
===============================================
package ecm.job;
import java.util.Date;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SimpleTrigger;
import org.quartz.impl.StdSchedulerFactory;
public class SimpleTriggerExample {
public static void main(String[] args) throws Exception {
Scheduler scheduler = new StdSchedulerFactory().getScheduler();
JobDetail job = new JobDetail();
job.setName("dummyJobName");
job.setJobClass(testjob.class);
//configure the scheduler time
SimpleTrigger trigger = new SimpleTrigger();
trigger.setName("dummyTriggerName");
trigger.setStartTime(new Date(System.currentTimeMillis()));
trigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);
trigger.setRepeatInterval(1000*30); //setup 30'
//schedule it
scheduler.start();
scheduler.scheduleJob(job, trigger);
}
}
Không có nhận xét nào:
Đăng nhận xét