Reputation: 64065
The idea would be to help determine the optimum stack size for a given Java application.
One thing that could be done with this information create a range-table of stack sizes which the threads could modify as they exit and which could be dumped periodically and at application exit.
EDIT: This is in the context of running on customer machines with real workloads which I can't get profiler access to.
EDIT2: In response to one answer, at (IIRC) 256Kb per thread, I have wondered for a while now how close that is to the reality of what's needed (I also wonder if this question might be not very relevant because perhaps stack space is allocated on demand). We have an application server which is based on message passing and highly threaded and runs on everything from an ARM handheld to octo-core Linux, to midrange and mainframes - it would be good to have a feeling for where (and if) we can trade stack space for heap on systems with many message handlers.
There are some similar questions which are of interest, but they are native/os-specific:
Upvotes: 13
Views: 12899
Reputation: 320
You may use the Runtime class to monitor the JVM memmory like this.
Runtime rt = Runtime.getRuntime();
System.out.println((rt.freeMemory() / 1024) + "/" + (rt.maxMemory() / 1024) + " kB");
Or you may use JConsole, JVisualVM e JInfo. You may get more information about these tools Here:
http://java.sun.com/developer/technicalArticles/J2SE/monitoring/
Upvotes: -3
Reputation: 165340
Stack memory will be hard to obtain.
Best you can do, and quite easily, is JVM memory usage via MemoryMXBean
.
Upvotes: 1
Reputation: 17904
Use JConsole-- you likely already have it: http://java.sun.com/j2se/1.5.0/docs/guide/management/jconsole.html http://openjdk.java.net/tools/svc/jconsole/
Upvotes: -1