package com.lixiaodao.task.quartz;
import java.text.ParseException;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.quartz.CronTriggerBean;
import com.lixiaodao.utils.DateUtil;
import com.lixiaodao.utils.StrUtils;
public class LixiaodaoCronTriggerBean extends CronTriggerBean{
private static final long serialVersionUID = 4625482606892589275L;
private static final Logger logger = LoggerFactory.getLogger(LixiaodaoCronTriggerBean.class);
private Map<String, String> cronExpressionMap;
private static final String TEN_YEAR_LATER = DateUtil.date2String(DateUtil.rollByYear(10), DateUtil.SDF_YYYY);
private static final String NOT_EXCUTE = "0 0 0 1 1 ? " + TEN_YEAR_LATER; /**设定一个10年后的时间,只要服务器10年内重启,定时任务就不会执行**/
/**
* 重写 父类的方法
*/
@Override
public void setCronExpression(String cronExpression) throws ParseException {
String localIp = "";//TODO ..这里是获取本地ip 的一种方式,内网或者外网,都可以,只要统一就ok
cronExpression = "";
if(cronExpressionMap != null){
cronExpression = cronExpressionMap.get(localIp);
}
if(StrUtils.isBlank(cronExpression)){
cronExpression = NOT_EXCUTE;
}
logger.debug("{} 使用 定时 {}",new Object[]{localIp,cronExpression});
super.setCronExpression(cronExpression);
}
}
import java.text.ParseException;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.quartz.CronTriggerBean;
import com.lixiaodao.utils.DateUtil;
import com.lixiaodao.utils.StrUtils;
public class LixiaodaoCronTriggerBean extends CronTriggerBean{
private static final long serialVersionUID = 4625482606892589275L;
private static final Logger logger = LoggerFactory.getLogger(LixiaodaoCronTriggerBean.class);
private Map<String, String> cronExpressionMap;
private static final String TEN_YEAR_LATER = DateUtil.date2String(DateUtil.rollByYear(10), DateUtil.SDF_YYYY);
private static final String NOT_EXCUTE = "0 0 0 1 1 ? " + TEN_YEAR_LATER; /**设定一个10年后的时间,只要服务器10年内重启,定时任务就不会执行**/
/**
* 重写 父类的方法
*/
@Override
public void setCronExpression(String cronExpression) throws ParseException {
String localIp = "";//TODO ..这里是获取本地ip 的一种方式,内网或者外网,都可以,只要统一就ok
cronExpression = "";
if(cronExpressionMap != null){
cronExpression = cronExpressionMap.get(localIp);
}
if(StrUtils.isBlank(cronExpression)){
cronExpression = NOT_EXCUTE;
}
logger.debug("{} 使用 定时 {}",new Object[]{localIp,cronExpression});
super.setCronExpression(cronExpression);
}
}