为什么要减小Java JVM线程堆栈的大小? [英] Why reduce the size of the Java JVM thread stack?

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

问题描述

我正在阅读有关处理Java中Out of Memory错误情况的文章(以及JBoss平台)我看到了这个减少threadstack大小的建议。

I was reading an article on handling Out Of Memory error conditions in Java (and on JBoss platform) and I saw this suggestion to reduce the size of the threadstack.

在最大内存错误情况下,如何减小threadstack的大小?

How would reducing the size of the threadstack help with a max memory error condition?

推荐答案

当Java创建一个新线程时,它会为该线程的堆栈预先分配一个固定大小的内存块。通过减小内存块的大小,可以避免内存不足,特别是如果你有很多线程 - 节省内存是减少堆栈大小乘以线程数。

When Java creates a new thread, it pre-allocates a fixed-size block of memory for that thread's stack. By reducing the size of that memory block, you can avoid running out of memory, especially if you have lots of threads - the memory saving is the reduction in stack size times the number of threads.

这样做的缺点是你增加了Stack Overflow错误的可能性。

The downside of doing this is that you increase the chance of a Stack Overflow error.

注意线程堆栈是在JVM堆之外创建的,因此,即使堆中有足够的可用内存,由于内存不足(或者地址空间不足,仍然无法创建线程堆栈,正如Tom Hawtin正确指出的那样)。

Note that the thread stacks are created outside of the JVM heap, so even if there's plenty of memory available in the heap, you can still fail to create a thread stack due to running out of memory (or running out of address space, as Tom Hawtin correctly points out).

这篇关于为什么要减小Java JVM线程堆栈的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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