update:自启动定时任务增加参数主机管控
This commit is contained in:
@@ -11,6 +11,7 @@ import com.adc.da.slrs.tsTask.entity.TbTask;
|
||||
import com.adc.da.slrs.tsTask.service.ITbTaskService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
import org.springframework.scheduling.support.CronTrigger;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -44,6 +45,10 @@ public class SchedulerConf {
|
||||
@Autowired
|
||||
ITbTaskService iTbTaskService;
|
||||
|
||||
@Value("${isNotScheduled}")
|
||||
private boolean isNotScheduled; //是否开启定时器
|
||||
|
||||
|
||||
/**
|
||||
* 初始化线程池任务调度
|
||||
*/
|
||||
@@ -112,25 +117,23 @@ public class SchedulerConf {
|
||||
* 根据ip开启定时任务
|
||||
*/
|
||||
public void startByIp() throws Exception {
|
||||
// InetAddress addr = InetAddress.getLocalHost();
|
||||
// log.info("Local HostAddress: "+addr.getHostAddress());
|
||||
// String hostname = addr.getHostName();
|
||||
// log.info("Local host name: "+hostname);
|
||||
List<String> addr = getIpAddress();
|
||||
//查询
|
||||
List<TbTask> tbTaskList = tbTaskDao.selectList(null);
|
||||
for (TbTask tbTask : tbTaskList) {
|
||||
if (addr == null){
|
||||
log.error("本机地址未获取到!!");
|
||||
break;
|
||||
}
|
||||
String ips = tbTask.getIp();
|
||||
String[] ipArray = ips.split(",");
|
||||
for (String realIp : ipArray) {
|
||||
if (addr.contains(realIp)) {
|
||||
log.info("本机ip地址:" + addr);
|
||||
this.start(tbTask.getId());
|
||||
log.info("执行了:" + tbTask.getTaskDesc());
|
||||
if(isNotScheduled){
|
||||
List<String> addr = getIpAddress();
|
||||
//查询
|
||||
List<TbTask> tbTaskList = tbTaskDao.selectList(null);
|
||||
for (TbTask tbTask : tbTaskList) {
|
||||
if (addr == null){
|
||||
log.error("本机地址未获取到!!");
|
||||
break;
|
||||
}
|
||||
String ips = tbTask.getIp();
|
||||
String[] ipArray = ips.split(",");
|
||||
for (String realIp : ipArray) {
|
||||
if (addr.contains(realIp)) {
|
||||
log.info("本机ip地址:" + addr);
|
||||
this.start(tbTask.getId());
|
||||
log.info("执行了:" + tbTask.getTaskDesc());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user