java - springboot线程数不断增加

标签 java multithreading spring-boot asynchronous

我有这个 springboot 应用程序,它大量使用带有 @Async 注释的线程,我没有配置 ThreadPoolTask​​Executor 因为据我所知,当线程说 thread-1 完成任务,其他任务可以使用回这个thread-1

但是从我从日志中观察到的,似乎有时线程数会上升到数千,如下所示:

2019-07-09 01:48:59.259  INFO 12592 --- [TaskExecutor-1] .s.d.r.c.TestingService :Something is running.
             ...... //Other threads running
2019-07-09 09:48:59.259  INFO 12592 --- [TaskExecutor-3432] .s.d.r.c.TestingService :Something is running.

我怀疑这些线程都没有被重用。

这是否意味着编号 3432 之前的那些线程没有被重用?还占内存?


更新:

我实际上检查了日志,例如这个 thread-255 已经完成,但是这个线程中没有任务被调度了。

2019-07-08 22:23:37.407  INFO 1 --- [TaskExecutor-255] c.d.v.c.j.impl.LoadSomethingAsync       : Something is running

最佳答案

是的,它是无限的。因为 @Async 默认依赖于 SimpleAsyncTaskExecutor。它在其 doc 中说

Supports limiting concurrent threads through the "concurrencyLimit" bean property. By default, the number of concurrent threads is unlimited.

关于java - springboot线程数不断增加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56940242/

相关文章:

C++ 线程安全累加器

c - pthread 不等待互斥锁 threadFinished

java - Intellij Idea 运行/调试配置和 Gradle 任务中的 SSH 隧道

angularjs - 如何为 Spring Boot 生成的 XSRF-Token cookie 设置 max-age

java - 使用 Spring 注解获取 HttpServletRequest 属性值

java - Android:加载应用程序时添加动画

java - 与扫描仪的混淆 (Big Java Ex 6.3)

java - jmh GC 分析器结果的值

java - Play Framework 2.2.1 : Create Http. 测试上下文

multithreading - 将多个嵌入式 javafx JFXPanel 管理到 swing tabbedpane 中