feat: There is no way the scheduled conf

This commit is contained in:
super_liu
2021-08-20 12:00:56 +08:00
parent 7c7be1065c
commit 4abeb55cf3
5 changed files with 55 additions and 0 deletions
@@ -0,0 +1,38 @@
package com.adc.da.scheduled;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Date;
@EnableScheduling
@Component
@Slf4j
public class ScheduledJob {
/**
* 根据配置文件设置是否开启定时器
*/
@Value("${isNotScheduled}")
private boolean isNotScheduled; //是否开启定时器
@Scheduled(cron="*/5 * * * * ?")
@Async
public void StandScheduledJob(){
if(isNotScheduled){
System.out.println(Thread.currentThread().getName() + " cron=0 0 1 1 * ? --- " + new Date()+"---START-01");
System.out.println(Thread.currentThread().getName() + " cron=0 0 1 1 * ? --- " + new Date()+"---End-01");
try{
Thread.sleep(2000);
}catch(Exception e){
}
}
}
}