小编sad*_*lit的帖子

在应用程序生命周期内创建的线程池的最大数量是否有限制?

考虑以下代码:

class Test {
    public static void main(String... args) {
        var t = new Test();
        while(true) {
            t.work();
        }
    }
    public void work() {
        ExecutorService executorService = Executors.newFixedThreadPool(10);

        try {
             /* Do work */
        }
        finally {
            executorService.shutdown();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在应用程序的生命周期中可以有多少个线程池(不是同时)是否有限制。

我尝试查看源代码并运行此测试一段时间,但似乎没有限制。一旦线程池计数器溢出会发生什么?

java concurrency multithreading threadpool

1
推荐指数
1
解决办法
55
查看次数

标签 统计

concurrency ×1

java ×1

multithreading ×1

threadpool ×1