开天辟地

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的更多相关文章

  1. Spring 5.x 、Spring Boot 2.x 、Spring Cloud 与常用技术栈整合

    项目 GitHub 地址:https://github.com/heibaiying/spring-samples-for-all 版本说明: Spring: 5.1.3.RELEASE Spring ...

  2. Spring 4 官方文档学习 Spring与Java EE技术的集成

    本部分覆盖了以下内容: Chapter 28, Remoting and web services using Spring -- 使用Spring进行远程和web服务 Chapter 29, Ent ...

  3. 【Spring】Spring的定时任务

    > 参考的优秀文章 Task Execution and Scheduling > 版本说明 <dependencies> <dependency> <gro ...

  4. Spring 5 (0) - Introduction & Index

    Spring Framework Reference Documentation I. Overview of Spring Framework . Getting Started with Spri ...

  5. Spring框架文档与API(4.3.6版本)

    http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/ Table of Contents I ...

  6. springboot集成schedule(深度理解)

    背景 在项目开发过程中,我们经常需要执行具有周期性的任务.通过定时任务可以很好的帮助我们实现. 我们拿常用的几种定时任务框架做一个比较: 从以上表格可以看出,Spring Schedule框架功能完善 ...

  7. SpringBoot标准Properties

    # =================================================================== # COMMON SPRING BOOT PROPERTIE ...

  8. springboot application.properties 常用完整版配置信息

    从springboot官方文档中扒出来的,留存一下以后应该会用到 # ================================================================= ...

  9. springboot集成schedule

    背景 在项目开发过程中,我们经常需要执行具有周期性的任务.通过定时任务可以很好的帮助我们实现. 我们拿常用的几种定时任务框架做一个比较: 从以上表格可以看出,Spring Schedule框架功能完善 ...

  10. java框架之SpringBoot(2)-配置

    规范 SpringBoot 使用一个全局的配置文件,配置文件名固定为 application.properties 或 application.yml .比如我们要配置程序启动使用的端口号,如下: s ...

随机推荐

  1. 新手小白需要了解的 Go 基础细节杂谈

    今日记录一下 学习 golang 这门语言遇到的一些比较特殊的细节,供大家参考. 所以,在我们输出内容的时候,可以包含很多的非 ASCII 码字符.实际上,Go 是天生支持 UTF-8 的,任何字符都 ...

  2. telnet命令安装

    1.[root@pld3bomdb01 ~]# yum install telnet-server 2.[root@pld3bomdb01 ~]# rpm -qa telnet* telnet-ser ...

  3. Java关键字以及标识符

    Java中有许多关键字,关键字是什么意思呢? 我用自己的分析来表达一下吧. Java就是源自于生活的,我们都有自己的名字.所以它也会有许多的名字,每个名字都有各自不同的特性(作用),都是系统定义好的. ...

  4. R的基本用法

    R变量的命名格式 必须以字母开头 只能包含字母.数字.下划线和.. 对大小写敏感 不能是保留关键字 数据类型(mode) numeric - (10.5, 55, 787) integer - (1L ...

  5. 第7章. 部署到GiteePages

    Gitee Pages 是一个免费的静态网页托管服务,您可以使用 Gitee Pages 托管博客.项目官网等静态网页.如果您使用过 Github Pages 那么您会很快上手使用 Gitee 的 P ...

  6. Gradio入门到进阶全网最详细教程[二]:快速搭建AI算法可视化部署演示(侧重参数详解和案例实践)

    Gradio入门到进阶全网最详细教程[二]:快速搭建AI算法可视化部署演示(侧重参数详解和案例实践) 相关文章:Gradio入门到进阶全网最详细教程[一]:快速搭建AI算法可视化部署演示(侧重项目搭建 ...

  7. Windows屏幕解锁服务原理及实现(1)

    https://github.com/zk2013/windows_remote_lock_unlock_screen 将生成的DLL注册至注册表 HKEY_LOCAL_MACHINE\SOFTWAR ...

  8. 16.ReentrantLock全解读

    大家好,我是王有志,欢迎和我聊技术,聊漂泊在外的生活.快来加入我们的Java提桶跑路群:共同富裕的Java人. 经历了AQS的前世和今生后,我们已经知道AQS是Java中提供同步状态原子管理,线程阻塞 ...

  9. ReactHub:我用 ChatGPT 搞了一个 React 的资源导航网站,谁有我用心啊!

    大家好,我是DOM哥. 图谱年年有,今年我来盘! 之前已经盘完了 Vue 的技术图谱,今天来盘 React 的. 我用 ChatGPT 开发了一个 React 的资源导航网站. 不管你是资深 Reac ...

  10. 2020-10-22:谈谈java中的LongAdder和LongAccumulator的相同点和不同点。

    福哥答案2020-10-22: 简单回答:相同点:都是多个单元操作.不同点:LongAdder相加,LongAccumulator自定义计算规则. 中级回答:相同点: LongAddr与LongAcc ...