From 4abeb55cf3ae2127c6698a18f78e091fe782f408 Mon Sep 17 00:00:00 2001 From: super_liu <396572590@qq.com> Date: Fri, 20 Aug 2021 12:00:56 +0800 Subject: [PATCH] feat: There is no way the scheduled conf --- adc-da-main/pom.xml | 5 +++ .../java/com/adc/da/AdcDaApplication.java | 2 + .../src/main/resources/application.properties | 5 +++ adc-da-slrs/pom.xml | 5 +++ .../com/adc/da/scheduled/ScheduledJob.java | 38 +++++++++++++++++++ 5 files changed, 55 insertions(+) create mode 100644 adc-da-slrs/src/main/java/com/adc/da/scheduled/ScheduledJob.java diff --git a/adc-da-main/pom.xml b/adc-da-main/pom.xml index cf4b3bc8..57f23e42 100644 --- a/adc-da-main/pom.xml +++ b/adc-da-main/pom.xml @@ -24,6 +24,11 @@ org.springframework.boot spring-boot-starter + + + org.springframework + spring-context-support + com.adc adc-da-convert diff --git a/adc-da-main/src/main/java/com/adc/da/AdcDaApplication.java b/adc-da-main/src/main/java/com/adc/da/AdcDaApplication.java index 1310d5ab..52969ab4 100644 --- a/adc-da-main/src/main/java/com/adc/da/AdcDaApplication.java +++ b/adc-da-main/src/main/java/com/adc/da/AdcDaApplication.java @@ -12,11 +12,13 @@ import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerF import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.context.annotation.Bean; +import org.springframework.scheduling.annotation.EnableScheduling; @EnableEurekaClient @EnableFeignClients @ServletComponentScan @SpringBootApplication(exclude = SecurityAutoConfiguration.class) +@EnableScheduling @MapperScan(value = {"com.adc.da.file.store"}) public class AdcDaApplication { diff --git a/adc-da-main/src/main/resources/application.properties b/adc-da-main/src/main/resources/application.properties index 50c4225d..b7b6adb0 100644 --- a/adc-da-main/src/main/resources/application.properties +++ b/adc-da-main/src/main/resources/application.properties @@ -152,3 +152,8 @@ elas.flag=true # 文档转换TCP通讯地址 convert.host=127.0.0.1 #convert.host=0.0.0.0 + +# ============================================================================= +# scheduled 配置 +# ============================================================================= +isNotScheduled=false \ No newline at end of file diff --git a/adc-da-slrs/pom.xml b/adc-da-slrs/pom.xml index cb647b83..951b761a 100644 --- a/adc-da-slrs/pom.xml +++ b/adc-da-slrs/pom.xml @@ -11,6 +11,11 @@ adc-da-slrs + + + org.springframework + spring-context-support + com.adc adc-da-base diff --git a/adc-da-slrs/src/main/java/com/adc/da/scheduled/ScheduledJob.java b/adc-da-slrs/src/main/java/com/adc/da/scheduled/ScheduledJob.java new file mode 100644 index 00000000..0937f48d --- /dev/null +++ b/adc-da-slrs/src/main/java/com/adc/da/scheduled/ScheduledJob.java @@ -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){ + } + } + } +}