mirror of https://github.com/elunez/eladmin
代码优化
parent
4b355067eb
commit
aaa373bdcf
|
@ -5,7 +5,6 @@ import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.scheduling.annotation.AsyncConfigurer;
|
import org.springframework.scheduling.annotation.AsyncConfigurer;
|
||||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
|
||||||
|
@ -37,7 +36,7 @@ public class AsyncTaskExecutePool implements AsyncConfigurer {
|
||||||
//活跃时间
|
//活跃时间
|
||||||
executor.setKeepAliveSeconds(config.getKeepAliveSeconds());
|
executor.setKeepAliveSeconds(config.getKeepAliveSeconds());
|
||||||
//线程名字前缀
|
//线程名字前缀
|
||||||
executor.setThreadNamePrefix("el-executor-");
|
executor.setThreadNamePrefix("el-async-");
|
||||||
// setRejectedExecutionHandler:当pool已经达到max size的时候,如何处理新任务
|
// setRejectedExecutionHandler:当pool已经达到max size的时候,如何处理新任务
|
||||||
// CallerRunsPolicy:不在新线程中执行任务,而是由调用者所在的线程来执行
|
// CallerRunsPolicy:不在新线程中执行任务,而是由调用者所在的线程来执行
|
||||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||||
|
@ -47,12 +46,9 @@ public class AsyncTaskExecutePool implements AsyncConfigurer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
|
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
|
||||||
return new AsyncUncaughtExceptionHandler() {
|
return (throwable, method, objects) -> {
|
||||||
@Override
|
log.error("===="+throwable.getMessage()+"====", throwable);
|
||||||
public void handleUncaughtException(Throwable throwable, Method method, Object... objects) {
|
log.error("exception method:"+method.getName());
|
||||||
log.error("=========================="+throwable.getMessage()+"=======================", throwable);
|
|
||||||
log.error("exception method:"+method.getName());
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ public class ThreadPoolExecutorUtil {
|
||||||
properties.getMaxPoolSize(),
|
properties.getMaxPoolSize(),
|
||||||
properties.getKeepAliveSeconds(),
|
properties.getKeepAliveSeconds(),
|
||||||
TimeUnit.SECONDS,
|
TimeUnit.SECONDS,
|
||||||
new ArrayBlockingQueue<Runnable>(properties.getQueueCapacity()),
|
new ArrayBlockingQueue<>(properties.getQueueCapacity()),
|
||||||
new TheadFactoryName()
|
new TheadFactoryName()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue