开发者

Is there any hard limit to a number of threads in Java?

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 lim开发者_Python百科it is lifted. Are both statements true?


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.)

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜