Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Eladmin
Commits
aaa373bd
Commit
aaa373bd
authored
Nov 01, 2019
by
dqjdda
Browse files
代码优化
parent
4b355067
Changes
2
Hide whitespace changes
Inline
Side-by-side
eladmin-system/src/main/java/me/zhengjie/config/thread/AsyncTaskExecutePool.java
View file @
aaa373bd
...
@@ -5,7 +5,6 @@ import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
...
@@ -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 {
...
@@ -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 {
...
@@ -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
());
}
};
};
}
}
}
}
eladmin-system/src/main/java/me/zhengjie/config/thread/ThreadPoolExecutorUtil.java
View file @
aaa373bd
...
@@ -20,7 +20,7 @@ public class ThreadPoolExecutorUtil {
...
@@ -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
()
);
);
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment