高级-09商品详情

业务代码篇......

一、环境搭建

  • 本地hosts修改,详情页前缀item.gulimall.html
  • nginx 存放静态文件,设置 item 路径到网关
  • 设置后台网关路由

二、返回值模型抽取

三、商品数据组合

四、详情页面渲染

五、异步编排优化

gulimall:
  thread:
    coreSize: 50
    max-Size: 200
    keep-alive-time: 6000
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@ConfigurationProperties(prefix = "gulimall.thread")
@Component
public class MyThreadConfigProperties {
    private Integer coreSize;
    private Integer maxSize;
    private Integer keepAliveTime;
}
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class MyThreadConfig {
    @Bean
    public ThreadPoolExecutor threadPoolExecutor(MyThreadConfigProperties pool) {
        return new ThreadPoolExecutor(pool.getCoreSize(), // 核心线程池的大小
                pool.getMaxSize(), // 最大线程池的大小
                pool.getKeepAliveTime(), // 空闲线程多长时间关闭
                TimeUnit.SECONDS, // 时间单位
                new LinkedBlockingQueue<>(10000), // 阻塞队列(队列长度)
                Executors.defaultThreadFactory(), // 线程工厂
                new ThreadPoolExecutor.AbortPolicy()); // 拒绝策略
    }
}
posted @ 2020-11-13 12:00  这杯Java有毒  阅读(100)  评论(0)    收藏  举报