weixin_慕前端4079947
2019-06-27 20:24:40浏览 1623
AbstractTask
package com.huihe.exam.task;
import com.huihe.exam.util.Tools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.Trigger;
import org.springframework.scheduling.support.CronTrigger;
public abstract class AbstractTask implements Runnable {
private SchedulerTask task;
private final Logger log = LoggerFactory.getLogger(AbstractTask.class);
public static final String TASK_SUCCESS = "2";
public static final String TASK_ERROR = "3";
public static final String TASK_DOING = "1";
public static final String TASK_WAITING = "0";
public AbstractTask (){
super();
}
@Override
public void run() {
log.info("父类run方法");
}
public abstract void success();
public abstract void error();
public abstract void doing();
public void stop(){
String taskId = task.getId();
if(TaskAdmin.scheduledFutureMap.containsKey(taskId)){
TaskAdmin.scheduledFutureMap.get(taskId).cancel(true);
TaskAdmin.scheduledFutureMap.remove(taskId);
log.info("移除任务【{}:{}】,当前任务池长度:{}", task.getTaskName(), taskId, TaskAdmin.scheduledFutureMap.size());
}
}
public SchedulerTask getTask() {
return task;
}
public void setTask(SchedulerTask task) {
this.task = task;
}
public Trigger getTrigger(){
return new CronTrigger(Tools.getCron(this.task.getStartTime()));
}
}