|
|
@ -131,7 +131,7 @@ public class SelectProRpListController extends BaseController
|
|
|
|
// 计算最优线程数
|
|
|
|
// 计算最优线程数
|
|
|
|
int CPU_CORES = Runtime.getRuntime().availableProcessors();
|
|
|
|
int CPU_CORES = Runtime.getRuntime().availableProcessors();
|
|
|
|
int OPTIMAL_THREADS = Math.min(
|
|
|
|
int OPTIMAL_THREADS = Math.min(
|
|
|
|
Math.max(CPU_CORES / 4, 4), // CPU核心数的1/4,但不少于4个线程
|
|
|
|
Math.max(CPU_CORES / 4, 8), // CPU核心数的1/4,但不少于8个线程
|
|
|
|
12 // 最大不超过12个线程
|
|
|
|
12 // 最大不超过12个线程
|
|
|
|
);
|
|
|
|
);
|
|
|
|
// 线程池配置
|
|
|
|
// 线程池配置
|
|
|
@ -151,7 +151,7 @@ public class SelectProRpListController extends BaseController
|
|
|
|
int totalBatches = (barcodes.size() + BATCH_SIZE - 1) / BATCH_SIZE; // 向上取整计算总批次数
|
|
|
|
int totalBatches = (barcodes.size() + BATCH_SIZE - 1) / BATCH_SIZE; // 向上取整计算总批次数
|
|
|
|
|
|
|
|
|
|
|
|
// 按顺序处理批次,但使用较小的并行窗口
|
|
|
|
// 按顺序处理批次,但使用较小的并行窗口
|
|
|
|
int PARALLEL_WINDOW = Math.min(4, OPTIMAL_THREADS); // 并行窗口大小,最多4个批次同时处理
|
|
|
|
int PARALLEL_WINDOW = Math.min(24, OPTIMAL_THREADS); // 并行窗口大小,最多12个批次同时处理
|
|
|
|
for (int windowStart = 0; windowStart < totalBatches; windowStart += PARALLEL_WINDOW) {
|
|
|
|
for (int windowStart = 0; windowStart < totalBatches; windowStart += PARALLEL_WINDOW) {
|
|
|
|
List<CompletableFuture<List<ProRpListPrint>>> windowFutures = new ArrayList<>();
|
|
|
|
List<CompletableFuture<List<ProRpListPrint>>> windowFutures = new ArrayList<>();
|
|
|
|
int windowEnd = Math.min(windowStart + PARALLEL_WINDOW, totalBatches);
|
|
|
|
int windowEnd = Math.min(windowStart + PARALLEL_WINDOW, totalBatches);
|
|
|
@ -181,12 +181,12 @@ public class SelectProRpListController extends BaseController
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
CompletableFuture<Void> windowComplete = CompletableFuture
|
|
|
|
CompletableFuture<Void> windowComplete = CompletableFuture
|
|
|
|
.allOf(windowFutures.toArray(new CompletableFuture[0]));
|
|
|
|
.allOf(windowFutures.toArray(new CompletableFuture[0]));
|
|
|
|
windowComplete.get(300, TimeUnit.SECONDS);
|
|
|
|
windowComplete.get(600, TimeUnit.SECONDS);
|
|
|
|
|
|
|
|
|
|
|
|
// 按提交顺序收集当前窗口的结果
|
|
|
|
// 按提交顺序收集当前窗口的结果
|
|
|
|
for (CompletableFuture<List<ProRpListPrint>> future : windowFutures) {
|
|
|
|
for (CompletableFuture<List<ProRpListPrint>> future : windowFutures) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
List<ProRpListPrint> batchResult = future.get(300, TimeUnit.SECONDS);
|
|
|
|
List<ProRpListPrint> batchResult = future.get(600, TimeUnit.SECONDS);
|
|
|
|
printInfo.addAll(batchResult);
|
|
|
|
printInfo.addAll(batchResult);
|
|
|
|
logger.info("当前处理进度: {}/{}",
|
|
|
|
logger.info("当前处理进度: {}/{}",
|
|
|
|
Math.min((windowStart + windowFutures.indexOf(future) + 1) * BATCH_SIZE, barcodes.size()),
|
|
|
|
Math.min((windowStart + windowFutures.indexOf(future) + 1) * BATCH_SIZE, barcodes.size()),
|
|
|
|