使用springboot怎么在高并发中提高吞吐量
更新:HHH   时间:2023-1-8


今天就跟大家聊聊有关使用springboot怎么在高并发中提高吞吐量,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

package com.zing.es.sample.config;
 
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 
import java.util.concurrent.ThreadPoolExecutor;
 
@Configuration
public class GlobalConfig {
 
 /**
   * 默认线程池线程池
   *
   * @return Executor
   */
  @Bean
  public ThreadPoolTaskExecutor defaultThreadPool() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    //核心线程数目
    executor.setCorePoolSize(16);
    //指定最大线程数
    executor.setMaxPoolSize(300);
    //队列中最大的数目
    executor.setQueueCapacity(50);
    //线程名称前缀
    executor.setThreadNamePrefix("defaultThreadPool_");
    //rejection-policy:当pool已经达到max size的时候,如何处理新任务
    //CALLER_RUNS:不在新线程中执行任务,而是由调用者所在的线程来执行
    //对拒绝task的处理策略
    executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
    //线程空闲后的最大存活时间
    executor.setKeepAliveSeconds(60);
    //加载
    executor.initialize();
    return executor;
  }
}

看完上述内容,你们对使用springboot怎么在高并发中提高吞吐量有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注天达云行业资讯频道,感谢大家的支持。

返回编程语言教程...