代码优化

pull/170/head
dqjdda 2019-11-01 09:16:44 +08:00
parent 4b355067eb
commit aaa373bdcf
2 changed files with 5 additions and 9 deletions

View File

@ -5,7 +5,6 @@ import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.lang.reflect.Method;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
@ -37,7 +36,7 @@ public class AsyncTaskExecutePool implements AsyncConfigurer {
//活跃时间
executor.setKeepAliveSeconds(config.getKeepAliveSeconds());
//线程名字前缀
executor.setThreadNamePrefix("el-executor-");
executor.setThreadNamePrefix("el-async-");
// setRejectedExecutionHandler当pool已经达到max size的时候如何处理新任务
// CallerRunsPolicy不在新线程中执行任务而是由调用者所在的线程来执行
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
@ -47,12 +46,9 @@ public class AsyncTaskExecutePool implements AsyncConfigurer {
@Override
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
return new AsyncUncaughtExceptionHandler() {
@Override
public void handleUncaughtException(Throwable throwable, Method method, Object... objects) {
log.error("=========================="+throwable.getMessage()+"=======================", throwable);
return (throwable, method, objects) -> {
log.error("===="+throwable.getMessage()+"====", throwable);
log.error("exception method:"+method.getName());
}
};
}
}

View File

@ -20,7 +20,7 @@ public class ThreadPoolExecutorUtil {
properties.getMaxPoolSize(),
properties.getKeepAliveSeconds(),
TimeUnit.SECONDS,
new ArrayBlockingQueue<Runnable>(properties.getQueueCapacity()),
new ArrayBlockingQueue<>(properties.getQueueCapacity()),
new TheadFactoryName()
);
}