Browse Source

发送异步邮件

wangming 8 tháng trước cách đây
mục cha
commit
aa26d5f150

+ 2 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/utils/ZhcxCommon.java

@@ -20,6 +20,7 @@ import com.rongwei.rwcommoncomponent.excel.vo.FormData;
 import com.rongwei.rwcommonentity.commonservers.domain.SysFileItemDo;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Component;
 import org.springframework.web.context.request.RequestContextHolder;
 import org.springframework.web.context.request.ServletRequestAttributes;
@@ -67,6 +68,7 @@ public class ZhcxCommon {
      *
      * @param notifyList
      */
+    @Async("inspectionCancelTaskExecutor")
     public void sendMsg(List<NotifyDto> notifyList) {
         if(ObjectUtil.isEmpty(notifyList)) {
             return ;

+ 21 - 0
business-server/src/main/java/com/rongwei/bsserver/config/AsyncConfig.java

@@ -5,6 +5,9 @@ import org.springframework.context.annotation.Configuration;
 import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 
+import java.util.concurrent.Executor;
+import java.util.concurrent.ThreadPoolExecutor;
+
 @Configuration
 @EnableAsync
 public class AsyncConfig {
@@ -18,4 +21,22 @@ public class AsyncConfig {
         executor.initialize();
         return executor;
     }
+
+    /**
+     *  取消邮件
+     *
+     * @return
+     */
+    @Bean(name = "inspectionCancelTaskExecutor")
+    public Executor rectifySaveTaskExecutor() {
+        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+        executor.setCorePoolSize(4); // 核心线程数
+        executor.setMaxPoolSize(8); // 最大线程数
+        executor.setQueueCapacity(100); // 队列大小
+        executor.setKeepAliveSeconds(60); // 线程空闲时间
+        executor.setThreadNamePrefix("inspection-cancel-thread-"); // 线程名前缀
+        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); // 拒绝策略
+        executor.initialize();
+        return executor;
+    }
 }

+ 1 - 1
business-server/src/main/resources/logback-spring.xml

@@ -25,7 +25,7 @@
         <append>true</append>
         <layout class="ch.qos.logback.classic.PatternLayout">
             <Pattern>
-                %d{yyyy-MM-dd HH:mm:ss} [%X{traceId}] %-5level -%msg%n
+                %d{yyyy-MM-dd HH:mm:ss} [%thread] [%X{traceId}] %-5level -%msg%n
             </Pattern>
         </layout>
     </appender>