-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
66 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 48 additions & 48 deletions
96
src/main/java/cn/com/ttblog/ssmbootstrap_table/util/Config.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 1,48 @@ | ||
package cn.com.ttblog.ssmbootstrap_table.util; | ||
|
||
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.AsyncConfigurer; | ||
import org.springframework.scheduling.annotation.EnableAsync; | ||
import java.lang.reflect.Method; | ||
import java.util.concurrent.Executor; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ThreadFactory; | ||
|
||
/** | ||
* 启用异步方法 | ||
* 发现在xml中配置<task:annotation-driven></task:annotation-driven>不生效, | ||
* 基于java config是生效的 | ||
* http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/scheduling/annotation/EnableAsync.html | ||
* http://docs.spring.io/spring/docs/4.2.9.RELEASE/spring-framework-reference/htmlsingle/#scheduling-annotation-support-async | ||
*/ | ||
@Configuration | ||
@EnableAsync | ||
public class Config implements AsyncConfigurer { | ||
|
||
/** | ||
* 自定义实现Executor | ||
* @return | ||
*/ | ||
@Override | ||
public Executor getAsyncExecutor() { | ||
ExecutorService executorService=Executors.newSingleThreadExecutor(new ThreadFactory() { | ||
@Override | ||
public Thread newThread(Runnable r) { | ||
return new Thread(r,"task"); | ||
} | ||
}); | ||
return executorService; | ||
} | ||
|
||
@Override | ||
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() { | ||
return new AsyncUncaughtExceptionHandler() { | ||
@Override | ||
public void handleUncaughtException(Throwable throwable, Method method, Object... objects) { | ||
System.out.printf("throwable:%s,method:%s,objects:%s",throwable,method,objects); | ||
} | ||
}; | ||
} | ||
} | ||
//package cn.com.ttblog.ssmbootstrap_table.util; | ||
// | ||
//import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; | ||
//import org.springframework.context.annotation.Configuration; | ||
//import org.springframework.scheduling.annotation.AsyncConfigurer; | ||
//import org.springframework.scheduling.annotation.EnableAsync; | ||
//import java.lang.reflect.Method; | ||
//import java.util.concurrent.Executor; | ||
//import java.util.concurrent.ExecutorService; | ||
//import java.util.concurrent.Executors; | ||
//import java.util.concurrent.ThreadFactory; | ||
// | ||
///** | ||
// * 启用异步方法 | ||
// * 发现在xml中配置<task:annotation-driven></task:annotation-driven>不生效, | ||
// * 基于java config是生效的 | ||
// * http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/scheduling/annotation/EnableAsync.html | ||
// * http://docs.spring.io/spring/docs/4.2.9.RELEASE/spring-framework-reference/htmlsingle/#scheduling-annotation-support-async | ||
// */ | ||
//@Configuration | ||
//@EnableAsync | ||
//public class Config implements AsyncConfigurer { | ||
// | ||
// /** | ||
// * 自定义实现Executor | ||
// * @return | ||
// */ | ||
// @Override | ||
// public Executor getAsyncExecutor() { | ||
// ExecutorService executorService=Executors.newSingleThreadExecutor(new ThreadFactory() { | ||
// @Override | ||
// public Thread newThread(Runnable r) { | ||
// return new Thread(r,"task"); | ||
// } | ||
// }); | ||
// return executorService; | ||
// } | ||
// | ||
// @Override | ||
// public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() { | ||
// return new AsyncUncaughtExceptionHandler() { | ||
// @Override | ||
// public void handleUncaughtException(Throwable throwable, Method method, Object... objects) { | ||
// System.out.printf("throwable:%s,method:%s,objects:%s",throwable,method,objects); | ||
// } | ||
// }; | ||
// } | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters