如何监控java线程堆栈的内存
在 Solaris x86 上的 32 位 jvm 上运行 Java EE 应用程序时,我收到 OutOfMemoryError:无法创建本机线程(或类似的内容)。
据我了解,这是因为jvm没有足够的内存用于新线程的堆栈。
我使用 JConsole 和 VisualVM 1.3 来监视应用程序,但我不知道这些工具中的“堆栈内存”被称为什么。在 VisualVM 中,我可以监视堆空间和永久代空间,而 JConsole 显示更多内存区域。这些内存区域中是否有为堆栈内存预留的?我知道这当然不是堆空间,但是 permgen 或非堆空间(在 JConsole 中称为)又如何呢?
While running a Java EE application on a 32 bit jvm on Solaris x86 I get an OutOfMemoryError:Cant create native thread (or something like that).
This is because the jvm does not have enough memory for the stack of the new thread as far as I understand it.
I use both JConsole and VisualVM 1.3 to monitor the application but I do not know what the "stackmemory" is called in these tools. In VisualVM I can monitor heapspace and permgen space while JConsole shows a few more memory areas. Is any of these memory areas set aside for stackmemory? I know it is not the heapspace of course but what about permgen or Non-heap (as it is called in JConsole)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您还可以尝试 JProfiler。
在 JProfiler 中,您可以从 CPU 分析视图中的线程视图和线程状态获取提示。这是截屏相同的。
您还可以检查以下内容来调试您的问题:(从链接引用)如果遇到此异常,可以执行一些操作。
平台)查看有多少线程
都积极参与这个过程。
定义的每个进程的线程数
由操作系统。如果极限
对于应用程序来说太低,尝试
提高每个进程的线程限制。
判断是否存在这样的代码
创建线程或连接(例如
作为 LDAP 连接)而不是
摧毁他们。你可以转储
Java线程查看是否有
已创建过多数量。
由应用程序打开,使
确保任何线程
应用程序创建被销毁。一个
企业应用程序 (.ear) 或 Web
应用程序(.war)运行在
长时间运行的 JVM。只因为
申请完成并不意味着
JVM 进程结束。这是
必须有一个免费的应用程序
它分配的任何资源。
另一种解决方案是
应用程序使用线程池
管理所需的线程。
您的代码的某些部分可能会创建大量线程。
尝试使用 ThreadPoolExecutor (线程池)在代码中限制应用程序中的线程,并相应地调整线程池大小以获得更好的性能。
You can also try JProfiler.
In JProfiler you can get hints from Thread views and Thread states in the CPU profiling views. Here is screencast for same.
You can also check following to debug your issue: (referenced from link) There are a few things to do if you encounter this exception.
platforms) to see how many threads
are active for this process.
number of threads per process defined
by the operating system. If the limit
is too low for the application, try
raising the per-process thread limit.
determine if there is code that is
creating threads or connections (such
as LDAP connections) and not
destroying them. You could dump the
Java threads to see if there are an
excessive number has been created.
are opened by the application, make
sure that any thread that the
application creates is destroyed. An
enterprise application (.ear) or Web
application (.war) runs under a
long-running JVM. Just because the
application is finished does not mean
that the JVM process ends. It is
imperative that an application free
any resources that it allocates.
Another solution would be for the
application to use a thread pool to
manage the threads needed.
Some part of your code may be creating lot of Threads.
Try using ThreadPoolExecutor (thread pooling) in your code to limit threads in your application, And tune your threadpool size accordingly for better performance.
您可以通过将应用程序生成的最大线程数乘以 1024 字节来估计它。
1024 字节是 java 线程的默认堆栈大小,可以使用 Xss JVM 参数进行更改。
为了避免本机内存 OOM,您可以通过减少 Java 堆(并为本机内存分配腾出空间)或减少 Java 堆栈大小(如果可以减少的话)来减少 JVM 内存使用量。
但是,如果应用程序的线程数无限增长,则必须使用池执行器来限制它。
You can estimate it by multiplying maximum number of thread your application generates with 1024 bytes.
1024 bytes is the default stack size of a java thread, and can be changed with the Xss JVM parameter.
To avoid native memory OOM, you can reduce JVM memory usage by reducing Java Heap (and make room for native memory allocation) or reducing the Java stack size if it can be reduced.
However, if thread number of your application growth indefinitely, you have to limit it using a pool executor.