diff --git a/fw-valhalla-common/src/main/java/cn/fw/valhalla/common/utils/ThreadPoolUtil.java b/fw-valhalla-common/src/main/java/cn/fw/valhalla/common/utils/ThreadPoolUtil.java index acdf997..2229871 100644 --- a/fw-valhalla-common/src/main/java/cn/fw/valhalla/common/utils/ThreadPoolUtil.java +++ b/fw-valhalla-common/src/main/java/cn/fw/valhalla/common/utils/ThreadPoolUtil.java @@ -1,17 +1,18 @@ package cn.fw.valhalla.common.utils; import cn.hutool.core.thread.ExecutorBuilder; +import com.google.common.util.concurrent.ThreadFactoryBuilder; import java.util.concurrent.ExecutorService; import java.util.concurrent.LinkedBlockingQueue; /** - * ThreadPoolUtl + * ThreadPoolUtil * * @author : kurisu * @version : 2.0 - * @className : ThreadPoolUtl - * @description : ThreadPoolUtl + * @className : ThreadPoolUtil + * @description : ThreadPoolUtil * @date : 2023-04-19 17:31 */ public class ThreadPoolUtil { @@ -21,7 +22,9 @@ public class ThreadPoolUtil { private ThreadPoolUtil() { this.executor = ExecutorBuilder.create() .setCorePoolSize(20) - .setMaxPoolSize(60) + .setMaxPoolSize(500) + .setThreadFactory(new ThreadFactoryBuilder().setNameFormat("valhalla-custom-%d").build()) + .setAllowCoreThreadTimeOut(true) .setWorkQueue(new LinkedBlockingQueue<>(4096)) .build(); } diff --git a/fw-valhalla-rpc/src/main/java/cn/fw/valhalla/rpc/member/MemberRpcService.java b/fw-valhalla-rpc/src/main/java/cn/fw/valhalla/rpc/member/MemberRpcService.java index 69cbddb..3dff148 100644 --- a/fw-valhalla-rpc/src/main/java/cn/fw/valhalla/rpc/member/MemberRpcService.java +++ b/fw-valhalla-rpc/src/main/java/cn/fw/valhalla/rpc/member/MemberRpcService.java @@ -8,7 +8,6 @@ import cn.fw.member.sdk.vo.BatchUserParam; import cn.fw.member.sdk.vo.MobileLocation; import cn.fw.member.sdk.vo.UserBaseInfoVO; import cn.fw.member.sdk.vo.UserRegistryVO; -import cn.fw.valhalla.common.utils.ThreadPoolUtil; import cn.fw.valhalla.rpc.member.dto.MemberUserDTO; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -22,7 +21,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; -import java.util.concurrent.CompletableFuture; import static org.apache.commons.lang3.Validate.isTrue; import static org.apache.commons.lang3.Validate.notNull; @@ -134,7 +132,7 @@ public class MemberRpcService { BeanUtils.copyProperties(user, userDTO); return userDTO; } catch (Exception e) { - log.error("调用Member系统根据会员手机号[{}]获取会员信息失败,原因:{}", mobile, e); + log.error("调用Member系统根据会员手机号[{}]获取会员信息失败", mobile, e); } return null; } @@ -171,29 +169,27 @@ public class MemberRpcService { return ""; } try { - CompletableFuture future1 = CompletableFuture.supplyAsync(() -> { - MobileUtil.Result result = MobileUtil.attribution(mobile); - String att = ""; - if (Objects.nonNull(result)) { - att = result.getProvince().concat(" ").concat(result.getCity()); - } - return att; - }, ThreadPoolUtil.getInstance().getExecutor()); + MobileUtil.Result result = MobileUtil.attribution(mobile); + String att = ""; + if (Objects.nonNull(result)) { + att = result.getProvince().concat(" ").concat(result.getCity()); + } + + if (!StringUtils.isBlank(att.trim())) { + return att.trim(); + } - CompletableFuture future2 = CompletableFuture.supplyAsync(() -> { - Message msg = functionApi.queryMobileLocation(mobile); - if (!msg.isSuccess()) { - return ""; - } - MobileLocation data = msg.getData(); - if (data != null) { - String province = data.getProvince(); - String city = data.getCity(); - return province.concat(" ").concat(city); - } + Message msg = functionApi.queryMobileLocation(mobile); + if (!msg.isSuccess()) { return ""; - }, ThreadPoolUtil.getInstance().getExecutor()); - return future1.applyToEither(future2, String::trim).join(); + } + MobileLocation data = msg.getData(); + if (data != null) { + String province = data.getProvince(); + String city = data.getCity(); + att = province.concat(" ").concat(city); + } + return att.trim(); } catch (Exception e) { log.warn("查询手机号归属地失败:", e); } diff --git a/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/follow/ClueApiBizService.java b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/follow/ClueApiBizService.java index 2b7558e..85e15f9 100644 --- a/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/follow/ClueApiBizService.java +++ b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/follow/ClueApiBizService.java @@ -109,7 +109,7 @@ public class ClueApiBizService { .map(vin -> CompletableFuture.runAsync(() -> list.add(queryClueDeadline(vin, groupId)), ThreadPoolUtil.getInstance().getExecutor())) .>toArray(CompletableFuture[]::new); try { - CompletableFuture.allOf(futureArr).get(); + CompletableFuture.allOf(futureArr).join(); } catch (Exception e) { log.error("Failed to query clue deadline", e); }