|
@@ -13,6 +13,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
@@ -29,8 +30,8 @@ public class SchedulingTaskService {
|
|
|
|
|
|
@Autowired
|
|
|
private ApplicationContext applicationContext;
|
|
|
- private ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(Constants.MAX_IMPORT_TASK_COUNT);
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
|
|
@Autowired
|
|
|
private ImportTaskConditionService importTaskConditionService;
|
|
|
|
|
@@ -39,8 +40,10 @@ public class SchedulingTaskService {
|
|
|
private List<ImportTaskAMVO> importTaskAMVOS;
|
|
|
|
|
|
public void startTask() {
|
|
|
- Integer freeCount = Constants.MAX_IMPORT_TASK_COUNT - executor.getActiveCount();
|
|
|
-
|
|
|
+ Integer freeCount = Constants.MAX_IMPORT_TASK_COUNT - threadPoolTaskExecutor.getActiveCount();
|
|
|
+ if(importTaskAMVOS==null){
|
|
|
+ importTaskAMVOS=new ArrayList<>();
|
|
|
+ }
|
|
|
// 当正在活跃的线程数小于最大线程数时
|
|
|
if (freeCount > 0) {
|
|
|
//查找任务
|
|
@@ -55,17 +58,19 @@ public class SchedulingTaskService {
|
|
|
|
|
|
if (importTaskList.size() > 0) {
|
|
|
// 装载任务信息
|
|
|
- importTaskAMVOS = this.loadTaskAMVOS(importTaskList);
|
|
|
+ List<ImportTaskAMVO> importTaskAMVOFromDbs = this.loadTaskAMVOS(importTaskList);
|
|
|
|
|
|
- for (int i = 0; i < importTaskAMVOS.size(); i++) {
|
|
|
+ for (int i = 0; i < importTaskAMVOFromDbs.size(); i++) {
|
|
|
importTaskList.get(i).setState(1);
|
|
|
importTaskList.get(i).updateById();
|
|
|
- importTaskAMVOS.get(i).setState(1);
|
|
|
- importTaskAMVOS.get(i).setThreadCounter(0);
|
|
|
- TaskThread taskThread = new TaskThread(importTaskAMVOS.get(i), applicationContext);
|
|
|
- executor.execute(taskThread);
|
|
|
+ importTaskAMVOFromDbs.get(i).setState(1);
|
|
|
+ importTaskAMVOFromDbs.get(i).setThreadCounter(0);
|
|
|
+ TaskThread taskThread = new TaskThread(importTaskAMVOFromDbs.get(i), applicationContext);
|
|
|
+ threadPoolTaskExecutor.execute(taskThread);
|
|
|
+ importTaskAMVOS.add(importTaskAMVOFromDbs.get(i));
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|