Java的最大线程数非常有限? [英] Java very limited on max number of threads?

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

问题描述

我们有一个带512Mb内存的小文本框。我们想在这个框中看到我们可以用Java创建多少个线程。令我们惊讶的是,我们不能创造很多。基本上,您可以使用-Xss设置的最小堆栈大小为64k。简单的数学将告诉你64 * 7000将消耗430Mb所以我们只能将它达到大约7000个线程左右然后我们遇到了这个错误:

We have a small text box with 512Mb of ram. We wanted to see how many threads we can create in Java in this box. To our surprise, we can't create many. Essentially the minimum stack size you can set with -Xss is 64k. Simple math will tell you that 64*7000 will consume 430Mb so we were only able to get it up to around 7000 threads or so and then we encountered this error:

java.lang.OutOfMemoryError: unable to create new native thread. 

这是Java的真正限制吗?每512Mb的内存我们只能挤出7k左右的线程?

Is this the true limit with Java? Per 512Mb of ram we can only squeeze in 7k number of threads or so?

推荐答案

使用异步IO(java nio)和你一起将不需要7k线程来支持7k客户端,处理io(5?)的几个线程就足够了。

看看 Netty ;)

Use asynchronous IO (java nio) and you'll don't need 7k threads to support 7k clients, a few threads for handling io (5?) will be enough.
Take a look at Netty ;)

每个客户的一个线程是一个非常糟糕的设计。

One thread for each client is a really bad design.

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

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