|
@@ -0,0 +1,33 @@
|
|
|
+package com.caimei365.user.config;
|
|
|
+
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
+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;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Description
|
|
|
+ *
|
|
|
+ * @author : Charles
|
|
|
+ * @date : 2021/11/12
|
|
|
+ */
|
|
|
+@Configuration
|
|
|
+@EnableAsync
|
|
|
+public class TaskPoolConfig {
|
|
|
+ @Bean("taskExecutor")
|
|
|
+ public Executor taskExecutor(){
|
|
|
+ ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
|
|
+ executor.setCorePoolSize(10);
|
|
|
+ executor.setMaxPoolSize(20);
|
|
|
+ executor.setQueueCapacity(200);
|
|
|
+ executor.setKeepAliveSeconds(60);
|
|
|
+ executor.setThreadNamePrefix("asyncTask-");
|
|
|
+ executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
|
|
+ executor.setWaitForTasksToCompleteOnShutdown(true);
|
|
|
+ executor.setAwaitTerminationSeconds(60);
|
|
|
+ return executor;
|
|
|
+ }
|
|
|
+}
|