Commit c93fb097 by fanjiaxin

联调问题处理

parent edc17019
Pipeline #71619 passed with stages
in 56 seconds
...@@ -7,10 +7,12 @@ import org.springframework.boot.SpringApplication; ...@@ -7,10 +7,12 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableAsync;
/** /**
* 项目启动类 * 项目启动类
*/ */
@EnableAsync
@ComponentScan(basePackages = "com.netease.yanxuan.wx.store.sharer") @ComponentScan(basePackages = "com.netease.yanxuan.wx.store.sharer")
@EnableApolloConfig @EnableApolloConfig
@EnableMissaClients(basePackages = "com.netease.yanxuan.wx.store.sharer") @EnableMissaClients(basePackages = "com.netease.yanxuan.wx.store.sharer")
......
package com.netease.yanxuan.wx.store.sharer.biz.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
/**
* 线程池配置类
*
* @author fanjiaxin
* @date 2024/6/12 15:55
*/
@Slf4j
@Configuration
@EnableAsync
public class ExecutorConfig {
/**
* 异步线程池
*/
@Bean(name = "asyncProductListServiceExecutor")
public Executor asyncProductListServiceExecutor() {
log.info("start asyncProductListServiceExecutor...");
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
//配置核心线程数
executor.setCorePoolSize(10);
//配置最大线程数
executor.setMaxPoolSize(20);
//配置队列大小
executor.setQueueCapacity(500);
//线程空闲时间
executor.setKeepAliveSeconds(30);
//配置线程池中的线程的名称前缀
executor.setThreadNamePrefix("async-product-list-service-executor-");
/**
* rejection-policy:当pool已经达到max size的时候,如何处理新任务
* CALLER_RUNS:不在新线程中执行任务,而是有调用者所在的线程来执行
*/
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
//等待所有任务完成再关闭
executor.setWaitForTasksToCompleteOnShutdown(true);
//最长等待时间,秒
executor.setAwaitTerminationSeconds(60);
//初始化执行器
executor.initialize();
return executor;
}
}
...@@ -29,6 +29,7 @@ import java.util.List; ...@@ -29,6 +29,7 @@ import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.concurrent.Executor;
/** /**
* @Description 商品-业务实现类 * @Description 商品-业务实现类
...@@ -44,6 +45,7 @@ public class ProductServiceImpl implements IProductService { ...@@ -44,6 +45,7 @@ public class ProductServiceImpl implements IProductService {
private final WeChatShopPromoteProductLinkRequest weChatShopPromoteProductLinkRequest; private final WeChatShopPromoteProductLinkRequest weChatShopPromoteProductLinkRequest;
private final WeChatShopSharerListRequest weChatShopSharerListRequest; private final WeChatShopSharerListRequest weChatShopSharerListRequest;
private final DrmSharerConfig drmSharerConfig; private final DrmSharerConfig drmSharerConfig;
private final Executor asyncProductListServiceExecutor;
@Override @Override
...@@ -120,7 +122,7 @@ public class ProductServiceImpl implements IProductService { ...@@ -120,7 +122,7 @@ public class ProductServiceImpl implements IProductService {
listVO.setProductId(item.getProduct_id()); listVO.setProductId(item.getProduct_id());
listVO.setProductPromotionLink(productInfo.getProduct_promotion_link()); listVO.setProductPromotionLink(productInfo.getProduct_promotion_link());
return listVO; return listVO;
}); }, asyncProductListServiceExecutor);
// 过滤空 // 过滤空
productList = Optional.of(productList).orElseGet(ArrayList::new) productList = Optional.of(productList).orElseGet(ArrayList::new)
.stream() .stream()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment