feat: There is no way the scheduled conf
This commit is contained in:
@@ -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){
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user