Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Xmx

 
Mohtashim Shaikh
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to read the -Xmx that my JVM PID is running with whether it is explicitly set or default.
Prefer a unix command (reading -Xmx in the unix shell script), if not then java code.

Thank,
Mohtashim
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do a


and then examine the resulting line. The last thing on the line is the full command used to start the program and include -Xmx etc if they were specified.

You might need to use the grep '-e' switch to specify a regular expression to more tightly control the matched lines but I leave that up to you.

If you don't actually know the PID then you can grep for the program jar name or class name instead (depends how you invoked it). Of course this will assume that you only have one copy running whereas specifying the PID and using a regex one can exactly match the program of interest.

You can go even further with the 'ps' command and extract just the fields of interest using the --format option. I can never remember the details so consult the 'man' page for 'ps' .

Edit : The information you need to work with can probably be obtained using


 
Mohtashim Shaikh
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for yr inputs, however I am still wanting to know how can we get the default -Xmxof a running JVM PID which does not have -Xmx set explicitly.

Regards,
Mohtashim
 
Rohan Dhapodkar
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use java.lang.Runtime.maxMemory() which will return max memory size that is set using -Xmx.
Oracle Java 5 documentation says that based on your hardware architecture java determines whether it's server configuration or client configuration and then it has some rules to set -Xmx and -Xms

http://download.oracle.com/javase/6/docs/technotes/tools/windows/java.html
http://download.oracle.com/javase/6/docs/technotes/guides/vm/gc-ergonomics.html
http://download.oracle.com/javase/6/docs/technotes/guides/vm/server-class.html
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rohan Dhapodkar wrote:You can use java.lang.Runtime.maxMemory() which will return max memory size that is set using -Xmx.l


It is my understanding that the OP only has the PID of the Java process so cannot get at any of the internal information. This is why I suggested parsing the output of the 'ps' command but obviously this fails if no -Xmx has been set.

One possibility is that if parsing the output of 'ps' does not produce a -Xmx value then the OP should assume the default value which must be documented somewhere. Of course this will only work if there is no way to set the -Xmx other than as an argument to 'java'.
 
Rohan Dhapodkar
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you really want to get those parameters of running JVM progrmatically, you can use JMX.
1. get your process id using jps or ps.
2. connect to running JVM . http://www.pongasoft.com/blog/yan/entry/connecting_to_a_local_vm/
3. get MemoryMxBean http://download.oracle.com/javase/7/docs/api/java/lang/management/ManagementFactory.html#getMemoryMXBean%28%29
4.then from MemoryMxBean you can get memory details . http://download.oracle.com/javase/7/docs/api/java/lang/management/MemoryMXBean.html

or you can use jconsole, which does the same thing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic