|
@@ -34,6 +34,7 @@ import java.time.Duration;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
import java.util.concurrent.CountDownLatch;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
+import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.function.Supplier;
|
|
import java.util.function.Supplier;
|
|
|
|
|
|
|
@@ -58,7 +59,7 @@ public class CommonCheck {
|
|
|
private static final Integer cardIdMode = 0;
|
|
private static final Integer cardIdMode = 0;
|
|
|
private static final Integer cardNoMode = 1;
|
|
private static final Integer cardNoMode = 1;
|
|
|
// 异步线程执行超时时间,以毫秒为单位
|
|
// 异步线程执行超时时间,以毫秒为单位
|
|
|
- private static final long VALIDATION_TIMEOUT = 300;
|
|
|
|
|
|
|
+ private static final long VALIDATION_TIMEOUT = 500;
|
|
|
|
|
|
|
|
private final BaseBusiness baseBusiness;
|
|
private final BaseBusiness baseBusiness;
|
|
|
private final InitBusiness initBusiness;
|
|
private final InitBusiness initBusiness;
|
|
@@ -100,10 +101,19 @@ public class CommonCheck {
|
|
|
|
|
|
|
|
// 使用CountDownLatch跟踪任务完成
|
|
// 使用CountDownLatch跟踪任务完成
|
|
|
CountDownLatch latch = new CountDownLatch(validationTasks.size());
|
|
CountDownLatch latch = new CountDownLatch(validationTasks.size());
|
|
|
|
|
+ AtomicBoolean cancelled = new AtomicBoolean(false);
|
|
|
|
|
|
|
|
// 提交所有验证任务
|
|
// 提交所有验证任务
|
|
|
- for (Supplier<R<ErrorInfo>> task : validationTasks) {
|
|
|
|
|
|
|
+ for (int i = 0, j = validationTasks.size(); i < j; i++) {
|
|
|
|
|
+ long starTime = System.currentTimeMillis();
|
|
|
|
|
+ final int taskIndex = i;
|
|
|
|
|
+ final Supplier<R<ErrorInfo>> task = validationTasks.get(taskIndex);
|
|
|
taskExecutor.execute(() -> {
|
|
taskExecutor.execute(() -> {
|
|
|
|
|
+ if (cancelled.get()) {
|
|
|
|
|
+ latch.countDown();
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
try {
|
|
try {
|
|
|
R<ErrorInfo> result = task.get();
|
|
R<ErrorInfo> result = task.get();
|
|
|
// 如果发现错误且尚未设置错误结果
|
|
// 如果发现错误且尚未设置错误结果
|
|
@@ -117,6 +127,7 @@ public class CommonCheck {
|
|
|
taskExecutor.getThreadPoolExecutor().getQueue().clear();
|
|
taskExecutor.getThreadPoolExecutor().getQueue().clear();
|
|
|
}
|
|
}
|
|
|
} finally {
|
|
} finally {
|
|
|
|
|
+ log.info("{} 完成,耗时:{} ms",getTaskName(taskIndex),System.currentTimeMillis()-starTime);
|
|
|
latch.countDown();
|
|
latch.countDown();
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
@@ -136,6 +147,14 @@ public class CommonCheck {
|
|
|
return createError(TradeStatusEnum.SysError);
|
|
return createError(TradeStatusEnum.SysError);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ private String getTaskName(int taskIndex) {
|
|
|
|
|
+ return switch (taskIndex) {
|
|
|
|
|
+ case 0 -> "参数验证";
|
|
|
|
|
+ case 1 -> "终端验证";
|
|
|
|
|
+ case 2 -> "账户验证";
|
|
|
|
|
+ default -> "未知任务";
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// region 消费参数校验
|
|
// region 消费参数校验
|
|
|
|
|
|