码迷,mamicode.com
首页 > 编程语言 > 详细

java 多线程-quarz

时间:2019-08-17 21:54:49      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:throws   nts   context   art   start   after   date   actor   try   

如视频导入文件和路径

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();

    }

}

java 多线程-quarz

标签:throws   nts   context   art   start   after   date   actor   try   

原文地址:https://blog.51cto.com/14437184/2430445

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!