feat: new threads are given names to help locate problems #213

This commit is contained in:
tjq 2021-02-09 22:53:28 +08:00
parent b4288225a0
commit ee9ed3c099
2 changed files with 8 additions and 3 deletions

View File

@ -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();
}
};
}

View File

@ -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;
}