寻找报错
parent
5fa93b9d7b
commit
d47e8e59f7
|
@ -29,7 +29,7 @@ import org.springframework.util.CollectionUtils;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
import static com.muyu.task.server.thread.OptimizedPrioritizedThreadPool.*;
|
||||
|
||||
|
@ -341,29 +341,72 @@ public class TaskInfoServiceImpl extends ServiceImpl<TaskInfoMapper, TaskInfo> i
|
|||
//log.info("执行{}查询的方法",sqlSelect);
|
||||
Result<DataValue[][]> tableValueResult = datasourceFeign.findTableValueToArray(basicId, sqlSelect, one, two);
|
||||
log.info(tableValueResult);
|
||||
|
||||
DataValue[][] data = tableValueResult.getData();
|
||||
log.info("执行{}查询的方法结束", sqlSelect);
|
||||
for (DataValue[] datum : data) {
|
||||
|
||||
executeTheRule(data,map,newBasicId,tableId);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void executeTheRule(DataValue[][] dataValues,HashMap<String,String> map, Long newBasicId,
|
||||
Long tableId) {
|
||||
// 创建一个单线程的ExecutorService
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
|
||||
// 创建一个链表来保存任务
|
||||
LinkedList<Callable<DataValue[][]>> tasks = new LinkedList<>();
|
||||
|
||||
// 初始化第一个任务
|
||||
tasks.add(() -> {
|
||||
return dataValues;
|
||||
});
|
||||
|
||||
// 创建任务链
|
||||
Future<DataValue[][]> currentFuture = null;
|
||||
for (int i = 1; i <= 4; i++) {
|
||||
final Future<DataValue[][]> finalCurrentFuture = currentFuture;
|
||||
Callable<DataValue[][]> task = () -> {
|
||||
|
||||
DataValue[][] prevResult = finalCurrentFuture.get();
|
||||
|
||||
return prevResult;
|
||||
};
|
||||
|
||||
// 提交任务并更新当前Future
|
||||
currentFuture = executor.submit(task);
|
||||
|
||||
// 等待当前任务完成
|
||||
try {
|
||||
currentFuture.get();
|
||||
System.out.println("Task " + i + " completed with result:");
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
System.out.println("Task execution failed: " + e.getMessage());
|
||||
break;
|
||||
}
|
||||
}
|
||||
try {
|
||||
DataValue[][] afterFilteringDataValue = currentFuture.get();
|
||||
for (DataValue[] datum : afterFilteringDataValue) {
|
||||
for (DataValue dataValue : datum) {
|
||||
String key = dataValue.getKey();
|
||||
String newKey = map.get(key);
|
||||
dataValue.setKey(newKey);
|
||||
}
|
||||
}
|
||||
log.info("{}查询结束", sqlSelect);
|
||||
log.info("执行{}添加的方法", sqlSelect);
|
||||
Result result = datasourceFeign.addProduct(newBasicId, tableId, data);
|
||||
Result result = datasourceFeign.addProduct(newBasicId, tableId, afterFilteringDataValue);
|
||||
log.info("{}添加结束", result);
|
||||
// for (List<DataValue> dataValues : tableValue) {
|
||||
// for (DataValue dataValue : dataValues) {
|
||||
// String key = dataValue.getKey();
|
||||
// String newKey = map.get(key);
|
||||
// dataValue.setKey(newKey);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
// 关闭ExecutorService
|
||||
executor.shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue