mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
feat: new threads are given names to help locate problems #213
This commit is contained in:
parent
b4288225a0
commit
ee9ed3c099
@ -3,6 +3,7 @@ package com.github.kfcfans.powerjob.server.common;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.concurrent.RejectedExecutionHandler;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
/**
|
||||
* 拒绝策略
|
||||
@ -13,6 +14,8 @@ import java.util.concurrent.RejectedExecutionHandler;
|
||||
@Slf4j
|
||||
public class RejectedExecutionHandlerFactory {
|
||||
|
||||
private static final AtomicLong COUNTER = new AtomicLong();
|
||||
|
||||
/**
|
||||
* 直接丢弃该任务
|
||||
* @param source log name
|
||||
@ -50,7 +53,9 @@ public class RejectedExecutionHandlerFactory {
|
||||
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);
|
||||
if (!p.isShutdown()) {
|
||||
new Thread(r).start();
|
||||
String threadName = source + "-T-" + COUNTER.getAndIncrement();
|
||||
log.info("[{}] create new thread[{}] to run job", source, threadName);
|
||||
new Thread(r, threadName).start();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ public class ThreadPoolConfig {
|
||||
executor.setQueueCapacity(0);
|
||||
executor.setKeepAliveSeconds(60);
|
||||
executor.setThreadNamePrefix("omsTimingPool-");
|
||||
executor.setRejectedExecutionHandler(RejectedExecutionHandlerFactory.newThreadRun("PowerJobTimingPool"));
|
||||
executor.setRejectedExecutionHandler(RejectedExecutionHandlerFactory.newThreadRun("PowerJob"));
|
||||
return executor;
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ public class ThreadPoolConfig {
|
||||
public TaskScheduler taskScheduler() {
|
||||
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
||||
scheduler.setPoolSize(Runtime.getRuntime().availableProcessors());
|
||||
scheduler.setThreadNamePrefix("omsSchedulerPool-");
|
||||
scheduler.setThreadNamePrefix("PowerJobSchedulePool-");
|
||||
scheduler.setDaemon(true);
|
||||
return scheduler;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user