|
1 | | -package cn.com.ttblog.ssmbootstrap_table.util; |
2 | | - |
3 | | -import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; |
4 | | -import org.springframework.context.annotation.Configuration; |
5 | | -import org.springframework.scheduling.annotation.AsyncConfigurer; |
6 | | -import org.springframework.scheduling.annotation.EnableAsync; |
7 | | -import java.lang.reflect.Method; |
8 | | -import java.util.concurrent.Executor; |
9 | | -import java.util.concurrent.ExecutorService; |
10 | | -import java.util.concurrent.Executors; |
11 | | -import java.util.concurrent.ThreadFactory; |
12 | | - |
13 | | -/** |
14 | | - * 启用异步方法 |
15 | | - * 发现在xml中配置<task:annotation-driven></task:annotation-driven>不生效, |
16 | | - * 基于java config是生效的 |
17 | | - * http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/scheduling/annotation/EnableAsync.html |
18 | | - * http://docs.spring.io/spring/docs/4.2.9.RELEASE/spring-framework-reference/htmlsingle/#scheduling-annotation-support-async |
19 | | - */ |
20 | | -@Configuration |
21 | | -@EnableAsync |
22 | | -public class Config implements AsyncConfigurer { |
23 | | - |
24 | | - /** |
25 | | - * 自定义实现Executor |
26 | | - * @return |
27 | | - */ |
28 | | - @Override |
29 | | - public Executor getAsyncExecutor() { |
30 | | - ExecutorService executorService=Executors.newSingleThreadExecutor(new ThreadFactory() { |
31 | | - @Override |
32 | | - public Thread newThread(Runnable r) { |
33 | | - return new Thread(r,"task"); |
34 | | - } |
35 | | - }); |
36 | | - return executorService; |
37 | | - } |
38 | | - |
39 | | - @Override |
40 | | - public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() { |
41 | | - return new AsyncUncaughtExceptionHandler() { |
42 | | - @Override |
43 | | - public void handleUncaughtException(Throwable throwable, Method method, Object... objects) { |
44 | | - System.out.printf("throwable:%s,method:%s,objects:%s",throwable,method,objects); |
45 | | - } |
46 | | - }; |
47 | | - } |
48 | | -} |
| 1 | +//package cn.com.ttblog.ssmbootstrap_table.util; |
| 2 | +// |
| 3 | +//import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; |
| 4 | +//import org.springframework.context.annotation.Configuration; |
| 5 | +//import org.springframework.scheduling.annotation.AsyncConfigurer; |
| 6 | +//import org.springframework.scheduling.annotation.EnableAsync; |
| 7 | +//import java.lang.reflect.Method; |
| 8 | +//import java.util.concurrent.Executor; |
| 9 | +//import java.util.concurrent.ExecutorService; |
| 10 | +//import java.util.concurrent.Executors; |
| 11 | +//import java.util.concurrent.ThreadFactory; |
| 12 | +// |
| 13 | +///** |
| 14 | +// * 启用异步方法 |
| 15 | +// * 发现在xml中配置<task:annotation-driven></task:annotation-driven>不生效, |
| 16 | +// * 基于java config是生效的 |
| 17 | +// * http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/scheduling/annotation/EnableAsync.html |
| 18 | +// * http://docs.spring.io/spring/docs/4.2.9.RELEASE/spring-framework-reference/htmlsingle/#scheduling-annotation-support-async |
| 19 | +// */ |
| 20 | +//@Configuration |
| 21 | +//@EnableAsync |
| 22 | +//public class Config implements AsyncConfigurer { |
| 23 | +// |
| 24 | +// /** |
| 25 | +// * 自定义实现Executor |
| 26 | +// * @return |
| 27 | +// */ |
| 28 | +// @Override |
| 29 | +// public Executor getAsyncExecutor() { |
| 30 | +// ExecutorService executorService=Executors.newSingleThreadExecutor(new ThreadFactory() { |
| 31 | +// @Override |
| 32 | +// public Thread newThread(Runnable r) { |
| 33 | +// return new Thread(r,"task"); |
| 34 | +// } |
| 35 | +// }); |
| 36 | +// return executorService; |
| 37 | +// } |
| 38 | +// |
| 39 | +// @Override |
| 40 | +// public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() { |
| 41 | +// return new AsyncUncaughtExceptionHandler() { |
| 42 | +// @Override |
| 43 | +// public void handleUncaughtException(Throwable throwable, Method method, Object... objects) { |
| 44 | +// System.out.printf("throwable:%s,method:%s,objects:%s",throwable,method,objects); |
| 45 | +// } |
| 46 | +// }; |
| 47 | +// } |
| 48 | +//} |
0 commit comments