How to monitor memory for java thread stacks

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)


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.

    链接地址: http://www.djcxy.com/p/82784.html

    上一篇: Linux上的JAVA堆大小监视

    下一篇: 如何监视Java线程堆栈的内存