xusirui před 2 měsíci
rodič
revize
340c546ac3

+ 53 - 0
src/main/java/com/gct/tools/etlcamelhuge/camelconfig/AsyncConfiguration.java

@@ -0,0 +1,53 @@
1
+//
2
+// Source code recreated from a .class file by IntelliJ IDEA
3
+// (powered by Fernflower decompiler)
4
+//
5
+
6
+package com.gct.tools.etlcamelhuge.camelconfig;
7
+
8
+import java.lang.reflect.Method;
9
+import org.slf4j.Logger;
10
+import org.slf4j.LoggerFactory;
11
+import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
12
+import org.springframework.context.annotation.Bean;
13
+import org.springframework.context.annotation.Configuration;
14
+import org.springframework.core.task.AsyncTaskExecutor;
15
+import org.springframework.scheduling.annotation.AsyncConfigurer;
16
+import org.springframework.scheduling.annotation.EnableAsync;
17
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
18
+
19
+@Configuration
20
+@EnableAsync
21
+public class AsyncConfiguration implements AsyncConfigurer {
22
+    public AsyncConfiguration() {
23
+    }
24
+
25
+    @Bean
26
+    public AsyncTaskExecutor asyncTaskExecutor() {
27
+        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
28
+        executor.setCorePoolSize(8);
29
+        executor.setMaxPoolSize(8);
30
+        return executor;
31
+    }
32
+
33
+    public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
34
+        return new LogAsyncUncaughtExceptionHandler();
35
+    }
36
+
37
+    class LogAsyncUncaughtExceptionHandler implements AsyncUncaughtExceptionHandler {
38
+        LogAsyncUncaughtExceptionHandler() {
39
+        }
40
+
41
+        public void handleUncaughtException(Throwable ex, Method method, Object... params) {
42
+            String paramLog = "";
43
+            int i = 0;
44
+
45
+            for(Object param : params) {
46
+                paramLog = paramLog + "param:" + i + "=>" + param.toString() + " ";
47
+            }
48
+
49
+            Logger log = LoggerFactory.getLogger(this.getClass());
50
+            log.error("Method:{} run error,Exception Message:{},StackTrace:{},input params:{}", new Object[]{method.getName(), ex.getMessage(), ex.getStackTrace(), paramLog});
51
+        }
52
+    }
53
+}