Hi, I am trying to monitor the java heap size dynamically. Does anybody know how to get the maxmium memory used in the process of running a piece of codes? Does the Runtime.maxMemory() do the trick? Thanks
There are a large number of profiler tools available that should help you with this. A popular commercial tool is YourKit, and it gets rave reviews. A free alternative is VisualVM, which I've used in the past and can provide a lot of insight.
If you like you can visually view a lot of values profiling your app with JConsole.
http://java.sun.com/developer/technicalArticles/J2SE/jconsole.html
Start your application with:
-Dcom.sun.management.jmxremote
and you app will be available for select when you start /bin/jconsole.exe
Yet another free alternative is to use Java-monitor. Have a look at this live demo. Just click on any of the servers to see detailed graphs on heap memory, non-heap memory, file descriptors, database pools and much more.
There is also the java.lang.management package. Use the ManagementFactory to get an MemoryMXBean
instance. It has methods to return a heap and a non-heap memory usage snapshot.
jstat -jc
jstat -gc jps -l | grep weblogic\.Server | awk {'print $1'}
1000 3
3 samples 1 one second see more here