Java中的许多线程是否存在硬限制? [英] Is there any hard limit to a number of threads in Java?

查看:138
本文介绍了Java中的许多线程是否存在硬限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一些 来源说,你对Java中的一些线程有一个硬限制(比如15k或者30k)即使你没有操作系统上限和无限的RAM。我还听说,在Java 7中,这个限制被解除了。这两个陈述都是真的吗?

Some sources say, that you have a hard limit to a number of threads in Java (like 15k or 30k) even if you have no OS cap per that and unlimited RAM. I also heard, that in Java 7 this limit is lifted. Are both statements true?

推荐答案

Java虚拟机规范未指定线程数限制。它们通常受可用堆栈空间量的限制,因为每个线程都有自己的私有堆栈。 (无法分配堆栈通常会在尝试创建新线程时触发OutOfMemory异常。)我相信线程池和其他机制也可用于限制线程数。 (例如, Sun使用此功能Java System Portal Server 用于限制事务数量。)

The Java Virtual Machine Specification doesn't specify a limit on the number of threads. They are typically limited by the amount of stack space available, since each thread gets its own private stack. (The inability to allocate a stack is what usually triggers an OutOfMemory exception when trying to create a new Thread.) I believe that thread pools and other mechanisms can be used to also limit the number of threads. (This is used, for example, by the Sun Java System Portal Server to throttle the number of transactions.)

不同的虚拟机实现可能会强加其他约束。例如,BlackBerry OS将非系统线程限制为每个应用程序16个,总计64个。我预计其他VM制造商也会施加额外的限制。我会向VM制造商咨询一下这个问题的答案。

Different virtual machine implementations may impose other constraints. For instance, the BlackBerry OS restricts non-system threads to 16 per application and 64 total. I expect that other VM makers have also imposed additional constraints. I'd check with the VM manufacturer for an answer to this.

这篇关于Java中的许多线程是否存在硬限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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