1.配置类

package cn.com.bonc.util;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; @Configuration
@EnableAsync
public class MyThread { private int corePoolSize = 10;//线程池维护线程的最少数量 private int maxPoolSize = 30;//线程池维护线程的最大数量 private int queueCapacity = 8; //缓存队列 private int keepAlive = 60;//允许的空闲时间 @Bean
public Executor myExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(corePoolSize);
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
executor.setThreadNamePrefix("mqExecutor-");
     // rejection-policy:当pool已经达到max size的时候,如何处理新任务  
        // CALLER_RUNS:不在新线程中执行任务,而是由调用者所在的线程来执行 
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); //对拒绝task的处理策略
executor.setKeepAliveSeconds(keepAlive);
executor.initialize();
return executor;
} }

2.注解使用

@Async("myExecutor") //配置类中的方法名

3.启动类添加

@EnableAsync

spring boot 线程池配置的更多相关文章

  1. Spring Boot 线程池

    参考 SpringBoot 线程池 程序猿DD-Spring Boot使用@Async实现异步调用:自定义线程池 如何优雅的使用和理解线程池 Spring Boot线程池的使用心得 博客园-Sprin ...

  2. Spring Boot 线程池的使用和扩展 - 转载

    转载:http://blog.csdn.net/boling_cavalry/article/details/79120268 1.实战环境 windowns10: jdk1.8: springboo ...

  3. spring boot: 线程池ThreadPoolTaskExecutor, 多线程

    由于项目里需要用到线程池来提高处理速度,记录一下spring的taskExecutor执行器来实现线程池. ThreadPoolTaskExecutor的配置在网上找了很多解释没找到,看了下Threa ...

  4. spring boot 数据库连接池配置

    HikariCP 连接池配置: http://stackoverflow.com/questions/29650501/hikaricp-starts-when-mvn-spring-bootrun- ...

  5. Spring Boot中如何配置线程池拒绝策略,妥善处理好溢出的任务

    通过之前三篇关于Spring Boot异步任务实现的博文,我们分别学会了用@Async创建异步任务.为异步任务配置线程池.使用多个线程池隔离不同的异步任务.今天这篇,我们继续对上面的知识进行完善和优化 ...

  6. Spring线程池配置模板设计(基于Springboot)

    目录 线程池配置模板 基础的注解解释 常用配置参数 配置类设计 线程池使用 ThreadPoolTaskExecutor源码 线程池配置模板 springboot给我们提供了一个线程池的实现,它的底层 ...

  7. 【转】spring boot application.properties 配置参数详情

    multipart multipart.enabled 开启上传支持(默认:true) multipart.file-size-threshold: 大于该值的文件会被写到磁盘上 multipart. ...

  8. Spring Boot Quartz 动态配置,持久化

    Quartz 是一个很强大的任务调度框架在SpringBoot中也很容易集成 添加依赖: <dependency> <groupId>org.springframework&l ...

  9. SpringBoot异步使用@Async原理及线程池配置

    前言 在实际项目开发中很多业务场景需要使用异步去完成,比如消息通知,日志记录,等非常常用的都可以通过异步去执行,提高效率,那么在Spring框架中应该如何去使用异步呢 使用步骤 完成异步操作一般有两种 ...

随机推荐

  1. HDU 1216 Assistance Required(暴力打表)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1216 Assistance Required Time Limit: 2000/1000 MS (Ja ...

  2. Xshell的使用

    1. Xshell 连接 ​ xshell 新建会话,主机地址,填下图中 inner addr 里的地址 ​ ​ 然后输入用户名,勾选记住用户名,确定 ​ ​ 输入密码 密码输入正确后即可连接成功 ​ ...

  3. 怎么得到scrollTop

    我们学习一个事件 :  页面滚动效果 window.onscroll = function() { 页面滚动语句  } 谷歌浏览器 和没有声明 DTD  <DOCTYPE     > : ...

  4. (mybatis)There is no getter for property named 'isEffective' in 'class java.lang.String

    原来代码: <select id="findSpecialOffer" resultType="com.lizard.back.model.SpecialOffer ...

  5. 【2018 ICPC南京网络赛 A】An Olympian Math Problem(数论题)

    Alice, a student of grade 6, is thinking about an Olympian Math problem, but she feels so despair th ...

  6. 用python爬取小说章节内容

    在学爬虫之前, 最好有一些html基础, 才能更好的分析网页. 主要是五步: 1.  获取链接 2. 正则匹配 3. 获取内容 4. 处理内容 5. 写入文件 代码如下: #导入相关model fro ...

  7. ABAP术语-IDOC

    IDOC 原文:http://www.cnblogs.com/qiangsheng/archive/2008/02/21/1075988.html Intermediate Document Inte ...

  8. CentOS7 64位下 MySQL5.7的安装与配置(YUM)

    趁着11.11的时候在阿里云上弄了一云服务ECS(作为自己的节日礼物 > _ <) ,系统为CentOS的,打算弄一个人博客之类的,这些天正在备案当中(不知得多久). 忙里偷闲,在中午休息 ...

  9. Flask中对MySQL的基本操作

    在Flask-SQLAlchemy中,插入.修改.删除操作,均由数据库会话管理. 会话用 db.session 表示.在准备把数据写入数据库前,要先将数据添加到会话中然后调用 commit() 方法提 ...

  10. 初学Splunk

    splunk简介 https://www.splunk.com/zh-hans_cn/download.html splunk 简体中文版手册 http://docs.splunk.com/Docum ...