- 1、加jar包:Quartz自己quartz-1.8.3.jar和依赖包commons-logging.jar 、slf4j-log4j12-1.5.10.jar 、slf4j-api-1.5.10.jar
-
2、一个类搞定!!!,直接run
import org.quartz.CronTrigger;
import org.quartz.Job;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;
import java.util.Date;
public class QuartzReport implements Job{
public void execute(JobExecutionContext cntxt) throws JobExecutionException {
System.out.println( "输出:"+cntxt.getJobDetail().getJobDataMap().get("name")+new Date());
}
public static void main(String[] args) {
try {
SchedulerFactory schedFact=new StdSchedulerFactory();
Scheduler sched=schedFact.getScheduler();
sched.start();
JobDetail jobDetail=new JobDetail("a","b",QuartzReport.class);
jobDetail.getJobDataMap().put("name","lucy");
CronTrigger trigger=new CronTrigger("c","d");
trigger.setCronExpression("0/1 * * * * ? " ); // 启动之后立即执行 每一秒继续重复。
sched.scheduleJob(jobDetail, trigger);
} catch (Exception e) {
e.printStackTrace();
}
}
}
*/
附:cronExpression配置说明
秒 0-59 , - * /
分 0-59 , - * /
小时 0-23 , - * /
日期 1-31 , - * ? / L W C
月份 1-12 或者 JAN-DEC , - * /
星期 1-7 或者 SUN-SAT , - * ? / L C #
年(可选) 留空, 1970-2099 , - * /