mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
feat: optimize RejectedExecutionHandlerFactory
This commit is contained in:
parent
614349370a
commit
3869b115ce
@ -21,10 +21,9 @@ public class RejectedExecutionHandlerFactory {
|
||||
* @param source log name
|
||||
* @return A handler for tasks that cannot be executed by ThreadPool
|
||||
*/
|
||||
public static RejectedExecutionHandler newReject(String source) {
|
||||
public static RejectedExecutionHandler newDiscard(String source) {
|
||||
return (r, p) -> {
|
||||
log.error("[{}] ThreadPool[{}] overload, the task[{}] will be dropped!", source, p, r);
|
||||
log.warn("[{}] Maybe you need to adjust the ThreadPool config!", source);
|
||||
log.error("[{}] ThreadPool[{}] overload, the task[{}] will be Discard, Maybe you need to adjust the ThreadPool config!", source, p, r);
|
||||
};
|
||||
}
|
||||
|
||||
@ -35,8 +34,7 @@ public class RejectedExecutionHandlerFactory {
|
||||
*/
|
||||
public static RejectedExecutionHandler newCallerRun(String source) {
|
||||
return (r, p) -> {
|
||||
log.warn("[{}] ThreadPool[{}] overload, the task[{}] will run by caller thread!", source, p, r);
|
||||
log.warn("[{}] Maybe you need to adjust the ThreadPool config!", source);
|
||||
log.error("[{}] ThreadPool[{}] overload, the task[{}] will run by caller thread, Maybe you need to adjust the ThreadPool config!", source, p, r);
|
||||
if (!p.isShutdown()) {
|
||||
r.run();
|
||||
}
|
||||
@ -50,8 +48,7 @@ public class RejectedExecutionHandlerFactory {
|
||||
*/
|
||||
public static RejectedExecutionHandler newThreadRun(String source) {
|
||||
return (r, p) -> {
|
||||
log.warn("[{}] ThreadPool[{}] overload, the task[{}] will run by a new thread!", source, p, r);
|
||||
log.warn("[{}] Maybe you need to adjust the ThreadPool config!", source);
|
||||
log.error("[{}] ThreadPool[{}] overload, the task[{}] will run by a new thread!, Maybe you need to adjust the ThreadPool config!", source, p, r);
|
||||
if (!p.isShutdown()) {
|
||||
String threadName = source + "-T-" + COUNTER.getAndIncrement();
|
||||
log.info("[{}] create new thread[{}] to run job", source, threadName);
|
||||
|
@ -46,7 +46,7 @@ public class ThreadPoolConfig {
|
||||
executor.setQueueCapacity(8192);
|
||||
executor.setKeepAliveSeconds(60);
|
||||
executor.setThreadNamePrefix("omsBackgroundPool-");
|
||||
executor.setRejectedExecutionHandler(RejectedExecutionHandlerFactory.newReject("PowerJobBackgroundPool"));
|
||||
executor.setRejectedExecutionHandler(RejectedExecutionHandlerFactory.newDiscard("PowerJobBackgroundPool"));
|
||||
return executor;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user