如何监控java线程堆栈的内存

发布于 2024-09-15 05:31:46 字数 306 浏览 2 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故事和酒 2024-09-22 05:31:46

您还可以尝试 JProfiler
在 JProfiler 中,您可以从 CPU 分析视图中的线程视图和线程状态获取提示。这是截屏相同的。

您还可以检查以下内容来调试您的问题:(从链接引用)如果遇到此异常,可以执行一些操作。

  • 使用 lsof -p PID 命令(Unix
    平台)查看有多少线程
    都积极参与这个过程。
  • 判断是否有最大值
    定义的每个进程的线程数
    由操作系统。如果极限
    对于应用程序来说太低,尝试
    提高每个进程的线程限制。
  • 检查应用程序代码
    判断是否存在这样的代码
    创建线程或连接(例如
    作为 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.

  • Use the lsof -p PID command (Unix
    platforms) to see how many threads
    are active for this process.
  • Determine if there is a maximum
    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.
  • Examine the application code to
    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.
  • If you find that too many connections
    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.

祁梦 2024-09-22 05:31:46

您可以通过将应用程序生成的最大线程数乘以 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文