Ver código fonte

实现异步任务超时,避免长时间占用核心线程

欧阳劲驰 1 mês atrás
pai
commit
de3ae0db17

+ 42 - 4
src/main/java/com/shkpr/service/alambizplugin/bizservice/GisSurveyCadConvertBizService.java

@@ -2,17 +2,23 @@ package com.shkpr.service.alambizplugin.bizservice;
 
 import com.global.base.log.LogLevelFlag;
 import com.global.base.log.LogPrintMgr;
+import com.shkpr.service.alambizplugin.commproperties.AsyncTaskProperties;
+import com.shkpr.service.alambizplugin.commproperties.GisSurveyCadConvertProperties;
 import com.shkpr.service.alambizplugin.components.GisSurveyCadConverter;
 import com.shkpr.service.alambizplugin.constants.CadEnum;
 import com.shkpr.service.alambizplugin.constants.GisSurveConvertStatusEnum;
 import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
 import com.shkpr.service.alambizplugin.dto.CommAsyncResult;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
 import org.springframework.stereotype.Component;
 import org.springframework.util.concurrent.ListenableFuture;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.time.Instant;
 import java.time.LocalDateTime;
 import java.util.Map;
 import java.util.Objects;
@@ -26,6 +32,7 @@ import java.util.concurrent.ExecutionException;
  * @since 1.0.0
  */
 @Component
+@EnableConfigurationProperties({GisSurveyCadConvertProperties.class})
 public class GisSurveyCadConvertBizService {
     /**
      * 任务缓存
@@ -41,17 +48,23 @@ public class GisSurveyCadConvertBizService {
     private final String mStrClassName;
     private final String mBizType;
 
+    private final AsyncTaskProperties asyncTaskProperties;
+    private final ThreadPoolTaskScheduler taskScheduler;
     private final GisSurveyCadConverter cadConverter;
 
 
-    public GisSurveyCadConvertBizService(GisSurveyCadConverter cadConverter) {
+    public GisSurveyCadConvertBizService(AsyncTaskProperties asyncTaskProperties
+            , @Qualifier("timeThreadPoolTaskScheduler") ThreadPoolTaskScheduler taskScheduler
+            , GisSurveyCadConverter cadConverter) {
         mStrClassName = "GisSurveyCadConvertBizService";
         mBizType = LogFlagBusiType.BUSI_GIS_SURVEY.toStrValue();
+        this.asyncTaskProperties = asyncTaskProperties;
+        this.taskScheduler = taskScheduler;
         this.cadConverter = cadConverter;
     }
 
     /**
-     * ca转换
+     * cad转换
      *
      * @param file       文件
      * @param convertId  转换id
@@ -131,14 +144,39 @@ public class GisSurveyCadConvertBizService {
             removeCache(convertId);
         }
         //异步执行cad转换查任务
-        ListenableFuture<CommAsyncResult<String>> checkFuture = cadConverter.cadConvert(convertId, inputStream, cadEnum);
+        ListenableFuture<CommAsyncResult<String>> future = cadConverter.cadConvert(convertId, inputStream, cadEnum);
+        //任务超时
+        taskScheduler.schedule(() -> {
+            if (!future.isCancelled() && !future.isDone() && stopTask(future)) {
+                removeCache(convertId);
+                LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
+                        , String.format(
+                                "cad转换超时,成功停止任务;转换id: %s"
+                                , convertId
+                        )
+                );
+            }
+        }, Instant.now().plusMillis(asyncTaskProperties.getCadConvertTimeout().toMillis()));
         //缓存任务句柄
-        TASK_CACHE.put(convertId, checkFuture);
+        TASK_CACHE.put(convertId, future);
         //缓存时间
         TIME_CACHE.put(convertId, LocalDateTime.now());
     }
 
     /**
+     * 停止任务
+     *
+     * @param future 任务id
+     * @return 关闭状态
+     */
+    private Boolean stopTask(ListenableFuture<?> future) {
+        //完成判断
+        if (future.isCancelled() || future.isDone()) return true;
+        //尝试清除任务
+        return future.cancel(true);
+    }
+
+    /**
      * 清除缓存
      *
      * @param convertId 转换id

+ 48 - 53
src/main/java/com/shkpr/service/alambizplugin/bizservice/GisSurveySystemCheckBizService.java

@@ -3,6 +3,7 @@ package com.shkpr.service.alambizplugin.bizservice;
 import com.global.base.log.LogLevelFlag;
 import com.global.base.log.LogPrintMgr;
 import com.shkpr.service.alambizplugin.apiparam.GisSurveyCheckParams;
+import com.shkpr.service.alambizplugin.commproperties.AsyncTaskProperties;
 import com.shkpr.service.alambizplugin.commproperties.GisSurveySystemCheckProperties;
 import com.shkpr.service.alambizplugin.components.GisSurveySystemCheckResultManager;
 import com.shkpr.service.alambizplugin.components.GisSurveySystemChecker;
@@ -14,17 +15,19 @@ import com.shkpr.service.alambizplugin.dbdao.services.intef.GisSurveyProjectInfo
 import com.shkpr.service.alambizplugin.dto.GisSurveySystemCheckId;
 import com.shkpr.service.alambizplugin.dto.GisSurveySystemCheckResult;
 import com.shkpr.service.alambizplugin.dto.GisSurveySystemCheckSubtask;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
 import org.springframework.stereotype.Component;
 import org.springframework.util.concurrent.ListenableFuture;
 
 import java.time.Duration;
+import java.time.Instant;
 import java.time.LocalDateTime;
-import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutionException;
-import java.util.stream.Collectors;
 
 /**
  * 系统检查管理service
@@ -33,6 +36,7 @@ import java.util.stream.Collectors;
  * @since 1.0.0
  */
 @Component
+@EnableConfigurationProperties({GisSurveySystemCheckProperties.class})
 public class GisSurveySystemCheckBizService {
     /**
      * 任务缓存
@@ -53,17 +57,26 @@ public class GisSurveySystemCheckBizService {
     private final String mStrClassName;
     private final String mBizType;
 
+    private final AsyncTaskProperties asyncTaskProperties;
     private final GisSurveySystemCheckProperties systemCheckProperties;
+    private final ThreadPoolTaskScheduler taskScheduler;
     private final GisSurveySystemCheckResultManager systemCheckFileManager;
     private final GisSurveySystemChecker systemChecker;
     private final GisSurveyProjectInfoService projectInfoService;
     private final GisSurveyJobInfoService jobInfoService;
 
-    public GisSurveySystemCheckBizService(GisSurveySystemCheckProperties systemCheckProperties, GisSurveySystemCheckResultManager systemCheckFileManager
-            , GisSurveySystemChecker systemChecker, GisSurveyProjectInfoService projectInfoService, GisSurveyJobInfoService jobInfoService) {
+    public GisSurveySystemCheckBizService(AsyncTaskProperties asyncTaskProperties
+            , GisSurveySystemCheckProperties systemCheckProperties
+            , @Qualifier("timeThreadPoolTaskScheduler") ThreadPoolTaskScheduler taskScheduler
+            , GisSurveySystemCheckResultManager systemCheckFileManager
+            , GisSurveySystemChecker systemChecker
+            , GisSurveyProjectInfoService projectInfoService
+            , GisSurveyJobInfoService jobInfoService) {
         mStrClassName = "GisSurveySystemCheckBizService";
         mBizType = LogFlagBusiType.BUSI_GIS_SURVEY.toStrValue();
+        this.asyncTaskProperties = asyncTaskProperties;
         this.systemCheckProperties = systemCheckProperties;
+        this.taskScheduler = taskScheduler;
         this.systemCheckFileManager = systemCheckFileManager;
         this.systemChecker = systemChecker;
         this.projectInfoService = projectInfoService;
@@ -144,43 +157,23 @@ public class GisSurveySystemCheckBizService {
      */
     public GisSurveySystemCheckResult cancelCheck(GisSurveyCheckParams params) {
         //任务标识
-        GisSurveySystemCheckId taskId = GisSurveySystemCheckId.generateId(params);
-        if (taskId == null) return GisSurveySystemCheckResult.fail(params);
+        GisSurveySystemCheckId systemCheckId = GisSurveySystemCheckId.generateId(params);
+        if (systemCheckId == null) return GisSurveySystemCheckResult.fail(params);
         //如无缓存,则直接返回不存在
-        if (!TASK_CACHE.containsKey(taskId)) return GisSurveySystemCheckResult.notExists(params);
+        if (!TASK_CACHE.containsKey(systemCheckId)) return GisSurveySystemCheckResult.notExists(params);
         //关闭检查任务
-        return stopTask(taskId) ? GisSurveySystemCheckResult.success(params) : GisSurveySystemCheckResult.fail(params);
-    }
+        if (stopTask(TASK_CACHE.get(systemCheckId))) {
+            removeCache(systemCheckId);
 
-    /**
-     * 过期任务
-     * <p>用于检查和使任务过期</p>
-     */
-    public void expireResult(Duration ttl) {
-        //获取超时的id
-        List<GisSurveySystemCheckId> systemCheckIds = TIME_CACHE.entrySet().stream()
-                .filter(entry ->
-                        Duration.between(entry.getValue(), LocalDateTime.now()).compareTo(ttl) > 0
-                )
-                .map(Map.Entry::getKey)
-                .collect(Collectors.toList());
-        //停止超时的任务并删除任务缓存
-        for (GisSurveySystemCheckId systemCheckId : systemCheckIds) {
-            //如任务不存在,则删除时间缓存
-            if (!TASK_CACHE.containsKey(systemCheckId)) TIME_CACHE.remove(systemCheckId);
-            //停用缓存
-            if (stopTask(systemCheckId)) TIME_CACHE.remove(systemCheckId);
-            else {
-                //打印报错信息
-                LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
-                        , String.format(
-                                "过期任务停止失败 ttl:%s 系统检查id:%s"
-                                , ttl
-                                , systemCheckId
-                        )
-                );
-            }
+            LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
+                    , String.format(
+                            "系统检查停止成功,清除缓存;系统检查id: %s"
+                            , systemCheckId
+                    )
+            );
+            return GisSurveySystemCheckResult.success(params);
         }
+        return GisSurveySystemCheckResult.fail(params);
     }
 
     /**
@@ -213,14 +206,26 @@ public class GisSurveySystemCheckBizService {
         if (previousFuture != null && (previousFuture.isDone() || previousFuture.isCancelled()))
             removeCache(systemCheckId);
         //异步执行系统检查任务
-        ListenableFuture<GisSurveySystemCheckResult> checkFuture = systemChecker.systemCheckTask(params,
+        ListenableFuture<GisSurveySystemCheckResult> future = systemChecker.systemCheckTask(params,
                 //缓存子任务句柄
                 subtask -> SUBTASK_CACHE.put(systemCheckId, subtask),
                 //删除子任务句柄
                 subtaskSystemCheckId -> SUBTASK_CACHE.remove(systemCheckId)
         );
+        //任务超时
+        taskScheduler.schedule(() -> {
+            if (!future.isCancelled() && !future.isDone() && stopTask(future)) {
+                removeCache(systemCheckId);
+                LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
+                        , String.format(
+                                "系统检查超时,成功停止任务;系统检查id: %s"
+                                , systemCheckId
+                        )
+                );
+            }
+        }, Instant.now().plusMillis(asyncTaskProperties.getSystemCheckTimeout().toMillis()));
         //缓存任务句柄
-        TASK_CACHE.put(systemCheckId, checkFuture);
+        TASK_CACHE.put(systemCheckId, future);
         //缓存时间
         TIME_CACHE.put(systemCheckId, LocalDateTime.now());
     }
@@ -228,24 +233,14 @@ public class GisSurveySystemCheckBizService {
     /**
      * 停止任务
      *
-     * @param systemCheckId 系统检查id
+     * @param future 系统检查任务
      * @return 关闭状态
      */
-    private Boolean stopTask(GisSurveySystemCheckId systemCheckId) {
-        ListenableFuture<GisSurveySystemCheckResult> future = TASK_CACHE.get(systemCheckId);
+    private Boolean stopTask(ListenableFuture<?> future) {
         //完成判断,完成删除缓存
-        if (future.isCancelled() || future.isDone()) {
-            removeCache(systemCheckId);
-            return true;
-        }
+        if (future.isCancelled() || future.isDone()) return true;
         //尝试清除任务
-        boolean cancel = future.cancel(true);
-        //清除成功,删除缓存
-        if (cancel) {
-            removeCache(systemCheckId);
-            return true;
-        }
-        return false;
+        return future.cancel(true);
     }
 
     /**

+ 38 - 3
src/main/java/com/shkpr/service/alambizplugin/bizservice/GisSurveyThirdExportBizService.java

@@ -2,15 +2,19 @@ package com.shkpr.service.alambizplugin.bizservice;
 
 import com.global.base.log.LogLevelFlag;
 import com.global.base.log.LogPrintMgr;
+import com.shkpr.service.alambizplugin.commproperties.AsyncTaskProperties;
 import com.shkpr.service.alambizplugin.components.GisSurveyThirdExporter;
 import com.shkpr.service.alambizplugin.constants.CommAsyncStatusEnum;
 import com.shkpr.service.alambizplugin.constants.FileTypeEnum;
 import com.shkpr.service.alambizplugin.constants.GisSurveConvertStatusEnum;
 import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
 import com.shkpr.service.alambizplugin.dto.CommAsyncResult;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
 import org.springframework.stereotype.Component;
 import org.springframework.util.concurrent.ListenableFuture;
 
+import java.time.Instant;
 import java.time.LocalDateTime;
 import java.util.Map;
 import java.util.Objects;
@@ -39,12 +43,18 @@ public class GisSurveyThirdExportBizService {
     private final String mStrClassName;
     private final String mBizType;
 
+    private final AsyncTaskProperties asyncTaskProperties;
+    private final ThreadPoolTaskScheduler taskScheduler;
     private final GisSurveyThirdExporter thirdExporter;
 
 
-    public GisSurveyThirdExportBizService(GisSurveyThirdExporter thirdExporter) {
+    public GisSurveyThirdExportBizService(AsyncTaskProperties asyncTaskProperties
+            , @Qualifier("timeThreadPoolTaskScheduler") ThreadPoolTaskScheduler taskScheduler
+            , GisSurveyThirdExporter thirdExporter) {
         mStrClassName = "GisSurveyThirdExportBizService";
         mBizType = LogFlagBusiType.BUSI_GIS_SURVEY.toStrValue();
+        this.asyncTaskProperties = asyncTaskProperties;
+        this.taskScheduler = taskScheduler;
         this.thirdExporter = thirdExporter;
     }
 
@@ -115,14 +125,39 @@ public class GisSurveyThirdExportBizService {
         //已结束判断,删除缓存
         if (previousFuture != null && (previousFuture.isDone() || previousFuture.isCancelled())) removeCache(jobId);
         //执行异步任务
-        ListenableFuture<CommAsyncResult<String>> checkFuture = thirdExporter.thirdExportTask(jobId, fileType);
+        ListenableFuture<CommAsyncResult<String>> future = thirdExporter.thirdExportTask(jobId, fileType);
+        //任务超时
+        taskScheduler.schedule(() -> {
+            if (!future.isCancelled() && !future.isDone() && stopTask(future)) {
+                removeCache(jobId);
+                LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
+                        , String.format(
+                                "第三方导出超时,成功停止任务;任务id: %s"
+                                , jobId
+                        )
+                );
+            }
+        }, Instant.now().plusMillis(asyncTaskProperties.getThirdExportTimeout().toMillis()));
         //缓存任务句柄
-        TASK_CACHE.put(jobId, checkFuture);
+        TASK_CACHE.put(jobId, future);
         //缓存时间
         TIME_CACHE.put(jobId, LocalDateTime.now());
     }
 
     /**
+     * 停止任务
+     *
+     * @param future 任务id
+     * @return 关闭状态
+     */
+    private Boolean stopTask(ListenableFuture<?> future) {
+        //完成判断
+        if (future.isCancelled() || future.isDone()) return true;
+        //尝试清除任务
+        return future.cancel(true);
+    }
+
+    /**
      * 清除缓存
      *
      * @param jobId 任务id

+ 40 - 51
src/main/java/com/shkpr/service/alambizplugin/bizservice/GisSurveyThirdImportBizService.java

@@ -3,18 +3,21 @@ package com.shkpr.service.alambizplugin.bizservice;
 import com.global.base.log.LogLevelFlag;
 import com.global.base.log.LogPrintMgr;
 import com.shkpr.service.alambizplugin.apiparam.GisSurveyThirdImportParams;
+import com.shkpr.service.alambizplugin.commproperties.AsyncTaskProperties;
 import com.shkpr.service.alambizplugin.components.GisSurveyThirdImporter;
 import com.shkpr.service.alambizplugin.constants.GisSurveyImportStatusEnum;
 import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
 import com.shkpr.service.alambizplugin.dto.GisSurveyThirdImportResult;
 import com.shkpr.service.alambizplugin.dto.GisSurveyThirdImportSubtask;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
 import org.springframework.stereotype.Component;
 import org.springframework.util.concurrent.ListenableFuture;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.time.Duration;
+import java.time.Instant;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.List;
@@ -22,7 +25,6 @@ import java.util.Map;
 import java.util.Objects;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutionException;
-import java.util.stream.Collectors;
 
 /**
  * 第三方导入管理service
@@ -50,12 +52,18 @@ public class GisSurveyThirdImportBizService {
     private final String mStrClassName;
     private final String mBizType;
 
+    private final AsyncTaskProperties asyncTaskProperties;
+    private final ThreadPoolTaskScheduler taskScheduler;
     private final GisSurveyThirdImporter thirdImporter;
 
 
-    public GisSurveyThirdImportBizService(GisSurveyThirdImporter thirdImporter) {
+    public GisSurveyThirdImportBizService(AsyncTaskProperties asyncTaskProperties
+            , @Qualifier("timeThreadPoolTaskScheduler") ThreadPoolTaskScheduler taskScheduler
+            , GisSurveyThirdImporter thirdImporter) {
         mStrClassName = "GisSurveySystemCheckBizService";
         mBizType = LogFlagBusiType.BUSI_GIS_SURVEY.toStrValue();
+        this.asyncTaskProperties = asyncTaskProperties;
+        this.taskScheduler = taskScheduler;
         this.thirdImporter = thirdImporter;
     }
 
@@ -134,38 +142,18 @@ public class GisSurveyThirdImportBizService {
         //如无缓存,则直接返回不存在
         if (!TASK_CACHE.containsKey(jobId)) return GisSurveyImportStatusEnum.NOT_EXISTS.getCode();
         //关闭检查任务
-        return stopTask(jobId) ? GisSurveyImportStatusEnum.SUCCESS.getCode() : GisSurveyImportStatusEnum.FAIL.getCode();
-    }
+        if (stopTask(TASK_CACHE.get(jobId))) {
+            removeCache(jobId);
 
-    /**
-     * 过期任务
-     * <p>用于检查和使任务过期</p>
-     */
-    public void expireResult(Duration ttl) {
-        //获取超时的id
-        List<String> jobIds = TIME_CACHE.entrySet().stream()
-                .filter(entry ->
-                        Duration.between(entry.getValue(), LocalDateTime.now()).compareTo(ttl) > 0
-                )
-                .map(Map.Entry::getKey)
-                .collect(Collectors.toList());
-        //停止超时的任务并删除任务缓存
-        for (String jobid : jobIds) {
-            //如任务不存在,则删除时间缓存
-            if (!TASK_CACHE.containsKey(jobid)) TIME_CACHE.remove(jobid);
-            //停用缓存
-            if (stopTask(jobid)) TIME_CACHE.remove(jobid);
-            else {
-                //打印报错信息
-                LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
-                        , String.format(
-                                "过期任务停止失败 ttl:%s 任务id:%s"
-                                , ttl
-                                , jobid
-                        )
-                );
-            }
+            LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
+                    , String.format(
+                            "第三方导入停止成功,清除缓存;任务id: %s"
+                            , jobId
+                    )
+            );
+            return GisSurveyImportStatusEnum.SUCCESS.getCode();
         }
+        return GisSurveyImportStatusEnum.FAIL.getCode();
     }
 
     /**
@@ -179,18 +167,29 @@ public class GisSurveyThirdImportBizService {
         //获取已存在的任务
         ListenableFuture<GisSurveyThirdImportResult> previousFuture = TASK_CACHE.get(jobId);
         //已结束判断,删除缓存
-        if (previousFuture != null && (previousFuture.isDone() || previousFuture.isCancelled())) {
+        if (previousFuture != null && (previousFuture.isDone() || previousFuture.isCancelled()))
             removeCache(params.getJobId());
-        }
         //异步执行第三方导入查任务
-        ListenableFuture<GisSurveyThirdImportResult> checkFuture = thirdImporter.thirdImportTask(params, inputStreams,
+        ListenableFuture<GisSurveyThirdImportResult> future = thirdImporter.thirdImportTask(params, inputStreams,
                 //缓存子任务句柄
                 subtask -> SUBTASK_CACHE.put(jobId, subtask),
                 //删除子任务句柄
                 subtaskSystemCheckId -> SUBTASK_CACHE.remove(jobId)
         );
+        //任务超时
+        taskScheduler.schedule(() -> {
+            if (!future.isCancelled() && !future.isDone() && stopTask(future)) {
+                removeCache(jobId);
+                LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
+                        , String.format(
+                                "第三方导入超时,成功停止任务;任务id: %s"
+                                , jobId
+                        )
+                );
+            }
+        }, Instant.now().plusMillis(asyncTaskProperties.getThirdImportTimeout().toMillis()));
         //缓存任务句柄
-        TASK_CACHE.put(jobId, checkFuture);
+        TASK_CACHE.put(jobId, future);
         //缓存时间
         TIME_CACHE.put(jobId, LocalDateTime.now());
     }
@@ -198,24 +197,14 @@ public class GisSurveyThirdImportBizService {
     /**
      * 停止任务
      *
-     * @param jobId 任务id
+     * @param future 任务
      * @return 关闭状态
      */
-    private Boolean stopTask(String jobId) {
-        ListenableFuture<GisSurveyThirdImportResult> future = TASK_CACHE.get(jobId);
+    private Boolean stopTask(ListenableFuture<?> future) {
         //完成判断,完成删除缓存
-        if (future.isCancelled() || future.isDone()) {
-            removeCache(jobId);
-            return true;
-        }
+        if (future.isCancelled() || future.isDone()) return true;
         //尝试清除任务
-        boolean cancel = future.cancel(true);
-        //清除成功,删除缓存
-        if (cancel) {
-            removeCache(jobId);
-            return true;
-        }
-        return false;
+        return future.cancel(true);
     }
 
     /**

+ 38 - 0
src/main/java/com/shkpr/service/alambizplugin/commproperties/AsyncTaskProperties.java

@@ -0,0 +1,38 @@
+package com.shkpr.service.alambizplugin.commproperties;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+import java.time.Duration;
+
+/**
+ * 异步任务属性
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+@Getter
+@Setter
+@ConfigurationProperties(prefix = "async-task")
+public class AsyncTaskProperties {
+    /**
+     * 系统检查超时时间
+     */
+    private Duration systemCheckTimeout;
+
+    /**
+     * 第三方导入超时时间
+     */
+    private Duration thirdImportTimeout;
+
+    /**
+     * 第三方导出超时时间
+     */
+    private Duration thirdExportTimeout;
+
+    /**
+     * cad转换超时时间
+     */
+    private Duration cadConvertTimeout;
+}

+ 0 - 2
src/main/java/com/shkpr/service/alambizplugin/commproperties/GisSurveyCadConvertProperties.java

@@ -3,7 +3,6 @@ package com.shkpr.service.alambizplugin.commproperties;
 import lombok.Getter;
 import lombok.Setter;
 import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.stereotype.Component;
 
 /**
  * cad转换配置
@@ -14,7 +13,6 @@ import org.springframework.stereotype.Component;
 @Getter
 @Setter
 @ConfigurationProperties(prefix = "cad-convert")
-@Component
 public class GisSurveyCadConvertProperties {
     /**
      * 栅格化最小宽度

+ 0 - 8
src/main/java/com/shkpr/service/alambizplugin/commproperties/GisSurveySystemCheckProperties.java

@@ -17,14 +17,6 @@ import java.time.Duration;
 @ConfigurationProperties(prefix = "system-check")
 public class GisSurveySystemCheckProperties {
     /**
-     * 系统检查任务超时时间
-     */
-    private Duration ttl;
-    /**
-     * 超时检查间隔(毫秒)
-     */
-    private Long ttlCheckInterval;
-    /**
      * 资源路径
      */
     private String resourcePath;

+ 0 - 27
src/main/java/com/shkpr/service/alambizplugin/commproperties/GisSurveyThirdImportProperties.java

@@ -1,27 +0,0 @@
-package com.shkpr.service.alambizplugin.commproperties;
-
-import lombok.Getter;
-import lombok.Setter;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-import java.time.Duration;
-
-/**
- * 第三方导入属性
- *
- * @author 欧阳劲驰
- * @since 1.0.0
- */
-@Getter
-@Setter
-@ConfigurationProperties(prefix = "third-import")
-public class GisSurveyThirdImportProperties {
-    /**
-     * 系统检查任务超时时间
-     */
-    private Duration ttl;
-    /**
-     * 超时检查间隔(毫秒)
-     */
-    private Long ttlCheckInterval;
-}

+ 0 - 2
src/main/java/com/shkpr/service/alambizplugin/commproperties/TempFileProperties.java

@@ -3,7 +3,6 @@ package com.shkpr.service.alambizplugin.commproperties;
 import lombok.Getter;
 import lombok.Setter;
 import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.stereotype.Component;
 
 import java.nio.file.Path;
 import java.time.Duration;
@@ -17,7 +16,6 @@ import java.time.Duration;
 @Getter
 @Setter
 @ConfigurationProperties(prefix = "temp-file")
-@Component
 public class TempFileProperties {
     /**
      * 检查周期

+ 4 - 1
src/main/java/com/shkpr/service/alambizplugin/configuration/ScheduleTaskConfiguration.java

@@ -2,9 +2,11 @@ package com.shkpr.service.alambizplugin.configuration;
 
 import com.global.base.log.LogLevelFlag;
 import com.global.base.log.LogPrintMgr;
+import com.shkpr.service.alambizplugin.commproperties.AsyncTaskProperties;
 import com.shkpr.service.alambizplugin.commtools.TimeTool;
 import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
 import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.boot.task.TaskExecutorBuilder;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
@@ -27,6 +29,7 @@ import java.util.concurrent.Executor;
 @Configuration
 @EnableScheduling
 @EnableAsync
+@EnableConfigurationProperties({AsyncTaskProperties.class})
 public class ScheduleTaskConfiguration implements SchedulingConfigurer, AsyncConfigurer {
     private final String mStrClassName;
 
@@ -59,7 +62,7 @@ public class ScheduleTaskConfiguration implements SchedulingConfigurer, AsyncCon
     /**
      * 定时任务多线程处理
      */
-    @Bean(destroyMethod = "shutdown")
+    @Bean(destroyMethod = "shutdown", name = "timeThreadPoolTaskScheduler")
     public ThreadPoolTaskScheduler taskScheduler() {
         ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
         scheduler.setPoolSize(2);

+ 2 - 2
src/main/java/com/shkpr/service/alambizplugin/configuration/TempFileConfiguration.java

@@ -5,8 +5,8 @@ import com.global.base.log.LogPrintMgr;
 import com.shkpr.service.alambizplugin.commproperties.TempFileProperties;
 import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
 import org.apache.commons.io.FileUtils;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.context.annotation.Configuration;
-import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
 
 import java.io.IOException;
@@ -24,7 +24,7 @@ import java.util.stream.Stream;
  * @since 1.0.0
  */
 @Configuration
-@EnableScheduling
+@EnableConfigurationProperties({TempFileProperties.class})
 public class TempFileConfiguration {
     /**
      * log

+ 2 - 37
src/main/java/com/shkpr/service/alambizplugin/globalmgr/ScheduleTaskMgr.java

@@ -3,17 +3,13 @@ package com.shkpr.service.alambizplugin.globalmgr;
 import com.global.base.log.LogLevelFlag;
 import com.global.base.log.LogPrintMgr;
 import com.global.base.thread.ThreadPoolProxy;
-import com.shkpr.service.alambizplugin.bizservice.GisSurveySystemCheckBizService;
-import com.shkpr.service.alambizplugin.bizservice.GisSurveyThirdImportBizService;
-import com.shkpr.service.alambizplugin.commproperties.GisSurveySystemCheckProperties;
-import com.shkpr.service.alambizplugin.commproperties.GisSurveyThirdImportProperties;
+
 import com.shkpr.service.alambizplugin.commtools.TimeTool;
 import com.shkpr.service.alambizplugin.components.GisDynamicDataSource;
 import com.shkpr.service.alambizplugin.components.locks.AlarmOrderLockMgr;
 import com.shkpr.service.alambizplugin.components.locks.SurveyBizLockMgr;
 import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
 import com.zaxxer.hikari.HikariDataSource;
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
@@ -24,22 +20,11 @@ import java.util.Map;
 import java.util.Set;
 
 @Component
-@EnableConfigurationProperties({GisSurveySystemCheckProperties.class,GisSurveyThirdImportProperties.class})
 public class ScheduleTaskMgr {
     private final String mStrClassName;
-    private final GisSurveySystemCheckProperties systemCheckProperties;
-    private final GisSurveyThirdImportProperties thirdImportProperties;
-    private final GisSurveySystemCheckBizService systemCheckBizService;
-    private final GisSurveyThirdImportBizService thirdImportBizService;
-
 
-    public ScheduleTaskMgr(GisSurveySystemCheckProperties systemCheckProperties,GisSurveyThirdImportProperties thirdImportProperties
-            , GisSurveySystemCheckBizService systemCheckBizService,GisSurveyThirdImportBizService thirdImportBizService) {
+    public ScheduleTaskMgr() {
         mStrClassName = this.getClass().getSimpleName();
-        this.systemCheckProperties = systemCheckProperties;
-        this.thirdImportProperties = thirdImportProperties;
-        this.systemCheckBizService = systemCheckBizService;
-        this.thirdImportBizService = thirdImportBizService;
     }
 
     @PostConstruct
@@ -52,26 +37,6 @@ public class ScheduleTaskMgr {
     public void destroy() throws Exception {
     }
 
-    /**
-     * 系统检查超时任务
-     */
-    @Scheduled(fixedRateString = "${system-check.ttl-check-interval}")
-    public void sysCheckTasksTtl() {
-        LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, LogFlagBusiType.BUSI_GIS_SURVEY.toStrValue(), mStrClassName
-                , String.format("开始执行系统检查超时任务 ttl:%s ======>", systemCheckProperties.getTtl()));
-        if (systemCheckProperties.getTtl() != null) systemCheckBizService.expireResult(systemCheckProperties.getTtl());
-    }
-
-    /**
-     * 第三方导入超时任务
-     */
-    @Scheduled(fixedRateString = "${third-import.ttl-check-interval}")
-    public void thirdImportTasksTtl() {
-        LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, LogFlagBusiType.BUSI_GIS_SURVEY.toStrValue(), mStrClassName
-                , String.format("开始执行第三方导入超时任务 ttl:%s ======>", thirdImportProperties.getTtl()));
-        if (thirdImportProperties.getTtl() != null) thirdImportBizService.expireResult(thirdImportProperties.getTtl());
-    }
-
     @Scheduled(cron = "${cron.refresh.timer.clock}")
     public void taskRefreshTimeRes() {
         TimeTool.refreshUTCTimeRes();

+ 5 - 9
src/main/resources/application.properties

@@ -139,24 +139,20 @@ fdfs.pool.max-wait-millis=5000
 des.proxy.fdfs=http://116.63.130.83:9999
 
 #=============系统检查========================
-#超时时间
-system-check.ttl=1h
-#检查周期(毫秒)
-system-check.ttl-check-interval=300000
 #资源路径
 system-check.resource-path=/home/kprCloud/alam_dma_kpr_plugin/sys-check-results/
 #结果滞后时间
 system-check.result-lag-duration=30m
-#=============第三方导入========================
-#超时时间
-third-import.ttl=1h
-#检查周期(毫秒)
-third-import.ttl-check-interval=300000
 #=============cad转换========================
 #栅格化最小宽度
 cad-convert.rasterization-min-width=800
 #栅格化最小高度
 cad-convert.rasterization-min-height=800
+#=============异步任务========================
+async-task.system-check-timeout=PT1H
+async-task.third-import-timeout=PT30M
+async-task.third-export-timeout=PT30M
+async-task.cad-convert-timeout=PT10M
 #=============临时文件========================
 temp-file.check-cycle=PT1M
 temp-file.resource-path=/home/kprCloud/alam_dma_kpr_plugin/temp-files/