You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.1 KiB
41 lines
1.1 KiB
package com.aiprose.sbquartz.quartz;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.quartz.*;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import javax.annotation.PostConstruct;
|
|
import javax.annotation.Resource;
|
|
import java.util.Date;
|
|
import java.util.UUID;
|
|
|
|
/**
|
|
* @author yanpeng
|
|
* @version 1.0
|
|
* @desc 任务配置
|
|
* @company 北京中经网软件有限公司
|
|
* @date 2020/12/23 16:05
|
|
*/
|
|
@Component
|
|
@Slf4j
|
|
public class DemoScheduler {
|
|
@Resource
|
|
private Scheduler scheduler;
|
|
|
|
@PostConstruct
|
|
public void init() throws SchedulerException {
|
|
startTaskJob();
|
|
scheduler.start();
|
|
}
|
|
|
|
public void startTaskJob() throws SchedulerException {
|
|
String uuid = UUID.randomUUID().toString();
|
|
JobDetail jobDetail = JobBuilder.newJob(DemoJob.class).withIdentity(uuid).build();
|
|
Date currentTime = new Date();
|
|
log.info("配置时间:{}",currentTime);
|
|
Date nowTime = new Date();
|
|
nowTime.setTime(nowTime.getTime() + 5000l);
|
|
Trigger subsys = TriggerBuilder.newTrigger().withIdentity(uuid).startAt(nowTime).build();
|
|
scheduler.scheduleJob(jobDetail, subsys);
|
|
}
|
|
}
|
|
|