Task Execution and Scheduling In SpringBoot
开天辟地
In the absence of an Executor bean in the context, Spring Boot auto-configures a ThreadPoolTaskExecutor with sensible defaults that can be automatically associated to asynchronous task execution (@EnableAsync) and Spring MVC asynchronous request processing.
在上下文中没有Executor bean的情况下,Spring Boot会自动配置一个ThreadPoolTaskExecutor,其中包含合理的默认值,可以自动关联到异步任务执行(@EnableAsync)和Spring MVC异步请求处理。
By default, Spring uses a SimpleAsyncTaskExecutor to actually run these methods asynchronously. But we can override the defaults at two levels: the application level or the individual method level.
Spring使用SimpleAsyncTaskExecutor来实际以异步方式运行这些方法。但是我们可以在两个级别上覆盖默认设置:应用程序级别或单个方法级别。
在@EnableAsync的javadoc中也有相关的一段话作为关联佐证:
By default, Spring will be searching for an associated thread pool definition: either a unique org.springframework.core.task.TaskExecutor bean in the context, or an java.util.concurrent.Executor bean named "taskExecutor" otherwise. If neither of the two is resolvable, a org.springframework.core.task.SimpleAsyncTaskExecutor will be used to process async method invocations. Besides, annotated methods having a void return type cannot transmit any exception back to the caller. By default, such uncaught exceptions are only logged.
要么是上下文中唯一的 org.springframework.core.task.TaskExecutor bean,要么是名为 "taskExecutor" 的 java.util.concurrent.Executor bean。如果这两者都无法解析,则会使用 org.springframework.core.task.SimpleAsyncTaskExecutor 来处理异步方法调用。此外,具有 void 返回类型的注释方法无法将任何异常传递回调用者。默认情况下,这样的未捕获异常仅会被记录日志。
解答
Spring Boot会自动配置一个ThreadPoolTaskExecutor, 它属于TaskExecutor, 如果是唯一的话就满足了相关条件, 不会再使用org.springframework.core.task.SimpleAsyncTaskExecutor运行@Async的方法
1. Task Execution
1.1. 注解
- @EnableAsync/@Async
1.2 重点类
ThreadPoolTaskExecutor
1.3 常规配置
spring.task.execution.pool.max-size=16
spring.task.execution.pool.queue-capacity=100
spring.task.execution.pool.keep-alive=10s
1.4 额外配置
默认的拒绝策略是AbortPolicy, 如果要修改的话就没有办法通过application.yaml设置了, 需要参考- How To Do @Async in Spring
2. Task Scheduling
1.1 注解
- @EnableScheduling/@Scheduled
1.2 重点类
ThreadPoolTaskScheduler
1.3 常规配置
spring.task.scheduling.thread-name-prefix=scheduling-
spring.task.scheduling.pool.size=2
1.4 额外配置
一般不涉及额外配置
Task Execution and Scheduling In SpringBoot的更多相关文章
- Spring 5.x 、Spring Boot 2.x 、Spring Cloud 与常用技术栈整合
项目 GitHub 地址:https://github.com/heibaiying/spring-samples-for-all 版本说明: Spring: 5.1.3.RELEASE Spring ...
- Spring 4 官方文档学习 Spring与Java EE技术的集成
本部分覆盖了以下内容: Chapter 28, Remoting and web services using Spring -- 使用Spring进行远程和web服务 Chapter 29, Ent ...
- 【Spring】Spring的定时任务
> 参考的优秀文章 Task Execution and Scheduling > 版本说明 <dependencies> <dependency> <gro ...
- Spring 5 (0) - Introduction & Index
Spring Framework Reference Documentation I. Overview of Spring Framework . Getting Started with Spri ...
- Spring框架文档与API(4.3.6版本)
http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/ Table of Contents I ...
- springboot集成schedule(深度理解)
背景 在项目开发过程中,我们经常需要执行具有周期性的任务.通过定时任务可以很好的帮助我们实现. 我们拿常用的几种定时任务框架做一个比较: 从以上表格可以看出,Spring Schedule框架功能完善 ...
- SpringBoot标准Properties
# =================================================================== # COMMON SPRING BOOT PROPERTIE ...
- springboot application.properties 常用完整版配置信息
从springboot官方文档中扒出来的,留存一下以后应该会用到 # ================================================================= ...
- springboot集成schedule
背景 在项目开发过程中,我们经常需要执行具有周期性的任务.通过定时任务可以很好的帮助我们实现. 我们拿常用的几种定时任务框架做一个比较: 从以上表格可以看出,Spring Schedule框架功能完善 ...
- java框架之SpringBoot(2)-配置
规范 SpringBoot 使用一个全局的配置文件,配置文件名固定为 application.properties 或 application.yml .比如我们要配置程序启动使用的端口号,如下: s ...
随机推荐
- DVWA上low级别反射型,存储型,DOM型XSS攻击获取用户cookie
1.什么是反射型 XSS 攻击? 反射型 XSS 是指应用程序通过 Web 请求获取不可信赖的数据,并在未检验数据是否存在恶意代码的情况下,将其发送给用户. 反射型 XSS 一般可以由攻击者构造带有恶 ...
- ROS机器人雷达跟随
ROS机器人雷达跟随 初始化 打开一个终端输入: ssh clbrobot@ip # 连接小车 roslaunch clbrobot bringup.launch # 激活主板 开启摄像头 开新终端输 ...
- docker启动mysql注意事项
1.编码问题 登录mysql伪终端 mysql查看编码 show variables like 'character%'; 宿主机在conf.d中添加配置my.cnf文件 [client] defau ...
- Git代码提交规范
1. 引言 思想,因人而异,难以重复 写代码时,每个人的习惯是不一样的,所以,引入了代码规范,为了省力,引入了自动格式化代码工具,前端工程中比较典型的自动格式化代码工具如:Prettier · Opi ...
- [C++核心编程] 5 文件操作
文章目录 5 文件操作 5.1文本文件 5.1.1写文件 5.1.2读文件 5.2 二进制文件 5.2.1 写文件 5.2.2 读文件 5 文件操作 程序运行时产生的数据都属于临时数据,程序一旦运行结 ...
- 我自己写了一个波场(Tron)本地网页版钱包
最近由于项目需要,需要给每个用户分配一个充币地址,考虑到钱包安全性和方便管理,于是自己动手写了一个本地网页版的钱包,附上源代码跟大家交流下. Github 源代码地址 钱包和项目是分离的,项目通过鉴权 ...
- 2022-12-20:二狗买了一些小兵玩具,和大胖一起玩, 一共有n个小兵,这n个小兵拍成一列, 第i个小兵战斗力为hi,然后他们两个开始对小兵进行排列, 一共进行m次操作,二狗每次操作选择一个数k,
2022-12-20:二狗买了一些小兵玩具,和大胖一起玩, 一共有n个小兵,这n个小兵拍成一列, 第i个小兵战斗力为hi,然后他们两个开始对小兵进行排列, 一共进行m次操作,二狗每次操作选择一个数k, ...
- 2020-12-09:TCP中,慢启动是什么?
福哥答案2020-12-09: 简单回答:乘法增大. 中级回答:cwnd拥塞窗口.rwnd接收窗口.MSS最大报文段长度.ssthresh慢开始门限.使用慢开始算法后,每经过一个传输轮次(即往返时延R ...
- Django4全栈进阶之路9 STATIC静态文件路径设置、MEDIA媒体文件路径设置
在 Django 4 中,可以在 settings.py 文件中设置 STATICFILES_DIRS 来指定应用程序静态文件所在的文件夹路径,设置 STATIC_ROOT 来指定收集所有应用程序静态 ...
- LVDS_33 support
在HR bank/HD bank中,支持LVDS的bank使用VCCO 3.3v供电,仅仅需要对端给过来的信号,满足标准的LVDS差模电压/共模电压的标准即可.如下截图: 限制: 仅能作为input ...