我有这个 springboot 应用程序,它大量使用带有 @Async
注释的线程,我没有配置 ThreadPoolTaskExecutor
因为据我所知,当线程说 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/