JVM中的最大线程数? [英] Maximum number of threads in a JVM?

查看:174
本文介绍了JVM中的最大线程数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java虚拟机可以维护的最大线程数是多少?

What are the maximum number of threads which can be maintained by the Java virtual machine?

我没有在原始问题中解释这一点,但我正在尝试对JVM进行基准测试,并希望尝试查看它可以同时维护多少个线程。

I did not explain this in my original question, but I am trying to benchmark the JVM and would like to try and see how many threads it can concurrently maintain.

在循环中创建线程直到抛出异常是一个选项,但是,我想知道是否有更好的方法来执行此操作。

Creating threads in a loop until an exception is thrown is an option, however, I would like to know if there is a better way to do this.

推荐答案

编写一个创建新线程的循环,直到它爆炸为止是确定的最终方法。你可能会看到性能在它实际死亡之前就会严重降低。

Writing a loop that creates new threads until it blows up is the definitive way to find out. You might well see performance degrade terribly before it actually dies.

我不知道JVM中是否有任何配置参数或其他内置限制我的头。我从未在实践中遇到过极限。当然,迟早你会耗尽内存,也许是其他资源。

I don't know if there's any configuration parameter or other built-in limit in the JVM off the top of my head. I've never run into a limit in practice. Of course sooner or later you will run out of memory, maybe some other resource.

我怀疑线程数本​​身没有限制,而是与线程关联的资源。也就是说,你可能会看到你可以拥有10,000个线程,如果它们只运行一个只带有几个字节数据的小类,但当它们各自拥有1000万个字符串的数组时,它会快速下降。

I suspect that there is not a limit on number of threads per se, but rather on resources associated with a thread. That is, you might see that you can have 10,000 threads if all of them are running just one small class with a few bytes of data each, but the number drops rapidly when they each have an array of 10 million strings.

这篇关于JVM中的最大线程数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆