定时任务处理

20230922-ljl-fixBug
qiushengjie 1 year ago
parent b41adc0cab
commit b8a50a7c43

@ -11,7 +11,23 @@ public abstract class TaskBaseService implements TaskHandler {
protected int corePoolSiz = 4;
protected int maxPoolSize = 10;
protected int queueCapacity = 500;
protected String TaskExecutorName = "TaskPool";
protected String taskExecutorName = "TaskPool";
public int getCorePoolSiz() {
return corePoolSiz;
}
public int getMaxPoolSize() {
return maxPoolSize;
}
public int getQueueCapacity() {
return queueCapacity;
}
public String getTaskExecutorName() {
return taskExecutorName;
}
public Executor getAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
@ -19,7 +35,7 @@ public abstract class TaskBaseService implements TaskHandler {
executor.setCorePoolSize(corePoolSiz + 1);
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
executor.setThreadNamePrefix(TaskExecutorName);
executor.setThreadNamePrefix(taskExecutorName);
executor.initialize();
return executor;
}
@ -66,7 +82,7 @@ public abstract class TaskBaseService implements TaskHandler {
int poolSize = mTaskPool.getPoolSize();
int maxPoolSize = mTaskPool.getMaxPoolSize();
int queueSize = mTaskPool.getThreadPoolExecutor().getQueue().size();
return String.format("异步方法从线程:%s中被调用TaskExecutor状态 - 活跃线程数:%d, 线程池大小:%d, 最大线程池大小:%d, 队列大小:%d",
return String.format("异步方法从线程:%s中被调用状态 - 活跃线程数:%d, 线程池大小:%d, 最大线程池大小:%d, 队列大小:%d",
currentThreadName, activeThreads, poolSize, maxPoolSize, queueSize);
}

@ -2,6 +2,7 @@ package com.ms.api.task;
import com.ms.api.common.StrObjMap;
import com.ms.api.common.TaskBaseService;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -18,8 +19,19 @@ import java.util.concurrent.Executor;
@Slf4j
public class TestTaskService extends TaskBaseService {
protected int corePoolSiz = 3; // 同时开启任务处理数量
protected String TaskExecutorName = "testTaskPool"; // 任务管理器名称
/**
*
*/
public int getCorePoolSiz() {
return 3;
}
/**
*
*/
public String getTaskExecutorName() {
return "testTaskPool";
}
@Resource(name = "testTaskPool")
protected Executor taskPool;

Loading…
Cancel
Save