一、前言
首先说一句,如果比较忙顺路点进来的,可以先收藏,有时间或用到了再看也行;
我相信很多人会有一个困惑,这个困惑和我之前一样,就是线程池这个玩意儿,感觉很高大上,用起来很fashion,本地环境测试环境调试毫无问题,但是一上线就出问题。
然后百度发现了很多数据,他们在谈论线程池的定制和各种配置参数。读完后,他们点了点头。这正是发生的事。他们决定果断地对其进行配置,但在线上仍然存在问题。[En]
Then Baidu found a lot of data that they were talking about the customization of thread pool and various configuration parameters. After reading it, they nodded. That's exactly what happened. They decided to configure it decisively, but there was still a problem online.
归根结底,这仍然是由于对自定义线程池的配置参数缺乏了解。本文将使用一个简单的案例来阐明线程池的配置以及如何配置在线环境。
[En]
In the final analysis, it is still due to the lack of understanding of the configuration parameters of the custom thread pool. This article will use a simple case to clarify the configuration of the thread pool and how to configure the online environment.
二、案例
1、编写案例
自定义一个线程池,并加上初始配置。
核心线程数10,最大线程数50,队列大小200,自定义线程池名称前缀为my-executor-,以及线程池拒绝策略为AbortPolicy,也是默认策略,表示直接放弃任务。
```java
package com.example.executor.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;