2

Java 线程池核心线程数自适应算法 探讨

 2 years ago
source link: https://www.v2ex.com/t/809295
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
V2EX  ›  Java

Java 线程池核心线程数自适应算法 探讨

  22yune · 10 小时 6 分钟前 · 663 次点击
场景:在指定时间内尽量请求多个服务的数据。使用线程池并发请求数据。

问题:核心线程数设置小了要等队列满了才加线程,队列小了缓冲不够大,队列大了,加线程要等太久;
核心线程数设置大了,可能太浪费,设置核心线程超时,设置大了也会导致前面的线程应超时销毁,后面的请求又一直创建线程。

解决思路:核心线程数开始设置最大线程数的一半,设置监测点:在核心线程超时销毁时,减小一半核心线程数,在队列达到现有线程数处理能力设定负载量时,增长一定比例核心线程数。核心线程数不能超过最大线程数。

大家觉得怎么样?

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK