Commit 7cd9c41b by liuyu

Merge branch 'feature' into 'release'

2023年05/16 线程池配置

See merge request !32
parents 229d039e 5f8b3d5a
......@@ -15,15 +15,15 @@ public class TaskPoolConfig {
public ThreadPoolTaskExecutor autMarkExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
// 配置核心线程数
executor.setCorePoolSize(15);
executor.setCorePoolSize(32);
// 配置最大线程数
executor.setMaxPoolSize(25);
executor.setMaxPoolSize(32);
// 配置线程池中的线程的名称前缀
executor.setThreadNamePrefix("autoMark-executor-");
executor.setQueueCapacity(50);
executor.setQueueCapacity(2000);
// rejection-policy:当pool已经达到max size的时候,如何处理新任务
// CALLER_RUNS:不在新线程中执行任务,而是有调用者所在的线程来执行
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
// 执行初始化
executor.initialize();
return executor;
......@@ -31,7 +31,7 @@ public class TaskPoolConfig {
@Bean("templateExecutor")
public ThreadPoolExecutorTimeout templateExecutor() {
return new ThreadPoolExecutorTimeout(1000L * 60 * 30, 10, 20,10000L,
TimeUnit.MILLISECONDS, 100, "模板任务线程池");
return new ThreadPoolExecutorTimeout(1000L * 60 * 30, 32, 32,10000L,
TimeUnit.MILLISECONDS, 200, "模板任务线程池");
}
}
......@@ -33,10 +33,12 @@ public class TaskServiceHandler {
for (TaskService taskService : SERVICE_LIST) {
TaskType taskType = taskService.supports(autoTask.getType());
if (Objects.nonNull(taskType)) {
if (taskService.thresholdWarn()) {
log.error("任务类型:{},当前运行任务已到达最大核心数", autoTask.getType());
try {
taskService.runTask(autoTask);
taskService.executorStatus();
} catch (Exception e) {
log.error("任务类型:{},执行异常:", taskType.getType(), e);
}
taskService.runTask(autoTask);
return taskType.getCacheId();
}
}
......
......@@ -6,6 +6,8 @@ import com.zhiwei.middleware.automatic.server.pojo.enums.TaskType;
public interface TaskService {
String executorLog = "name:{}任务线程池信息:当前活跃线程{},队列长度:{}";
/**
* 任务类型匹配
* @return 名字
......@@ -22,5 +24,5 @@ public interface TaskService {
* 任务运行阈值预警
* @return 是否进行预警
*/
boolean thresholdWarn();
void executorStatus();
}
......@@ -81,8 +81,9 @@ public class TaskServiceCommon extends BaseTaskTypePair<TaskServiceCommon.TaskCo
}
@Override
public boolean thresholdWarn() {
return autoMarkExecutor.getActiveCount() == autoMarkExecutor.getCorePoolSize();
public void executorStatus() {
log.info(executorLog, "自动标注",autoMarkExecutor.getThreadPoolExecutor().getActiveCount(),
autoMarkExecutor.getThreadPoolExecutor().getQueue().size());
}
/**
......
......@@ -90,9 +90,8 @@ public class TaskServiceTemplate extends BaseTaskTypePair<TaskServiceTemplate.Ta
}
@Override
public boolean thresholdWarn() {
// return executor.getActiveCount() == executor.getCorePoolSize();
return false;
public void executorStatus() {
log.info(executorLog, "模板聚合",executor.getActiveCount(), executor.getQueue().size());
}
private void templateRecordClean(AutoTask autoTask) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment