您好,登錄后才能下訂單哦!
如視頻導入文件和路徑
package quartz;
import java.util.Date;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
public class HelloJob implements Job {
public HelloJob() {
}
public void execute(JobExecutionContext context)
throws JobExecutionException {
System.out.println("---start---");
System.out.println("Hello World! - " + new Date());
System.out.println("---end---");
}
}
第二個class
package quartz;
import static org.quartz.JobBuilder.newJob;
import static org.quartz.TriggerBuilder.newTrigger;
import static org.quartz.DateBuilder.evenSecondDateAfterNow;
import java.util.Date;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.Trigger;
import org.quartz.impl.StdSchedulerFactory;
/*
quarz
*/
public class SimpleExample {
public void run() throws Exception {
//1、創建Scheduler的工廠
SchedulerFactory sf = new StdSchedulerFactory();
//2、從工廠中獲取調度器
Scheduler sched = sf.getScheduler();
//3、創建JobDetail
JobDetail job = newJob(HelloJob.class).withIdentity("job1", "group1").build();
//時間,下一秒
Date runTime = evenSecondDateAfterNow();
//4、觸發器
Trigger trigger = newTrigger().withIdentity("trigger1", "group1").startAt(runTime).build();
//5、注冊任務和觸發條件
sched.scheduleJob(job, trigger);
//6、啟動
sched.start();
try {
// 5秒后停止
Thread.sleep(5L*1000L);
// executing...
} catch (Exception e) {
//
}
sched.shutdown(true);
}
public static void main(String[] args) throws Exception {
SimpleExample example = new SimpleExample();
example.run();
}
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。