• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

code to find available jvm's

 
Anuj Troy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
need to write a command line java program to list all the available jvm's and list out their allocated heap memory and used heap memory. can someone give me a sample code.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you tried so far?
 
Anuj Troy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
honestly i dont have much knowledge about how to access jvm and how to get the heap size and other details programatically , so have just searched google.

i understand i may not be asking the right questions...

i am looking for some direction here so that i can understand this concept of accessing jvm and get some information from the jvm (just like some profiler)
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34860
369
Eclipse IDE Java VI Editor
 
Anuj Troy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no not JMX. maybe what i am looking for is how can i use JVM TI? i want to access the JVM (Java Virtual Machine) and just display its memory state. for that i need to be able to locate the JVM first and then i need some way to talk to jvm so that i can get how much heap is allocated to it, how much is being used and how much is free..
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And this has to work across multiple JVMs right? Then JMX is a fairly good solution (will work for JDK 1.4+ IIRC)
 
Gaurav Purandare
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anuj Troy wrote:need to write a command line java program to list all the available jvm's and list out their allocated heap memory and used heap memory. can someone give me a sample code.


Try Attach API, it gives you methods to view the available local jvm's along with their process id's
you can then attach to each jvm and use the java management extentions to get the information regarding the memory usage
you can connect to the platform MbeanServer on each jvm's if it already exists
else create one dynamically
 
James Basller
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anuj Troy wrote:need to write a command line java program to list all the available jvm's and list out their allocated heap memory and used heap memory. can someone give me a sample code.



Hi,

I think JMX would be the best solution for JVM.

Thanks!!!
 
Gaurav Purandare
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

the above code gives you the list of all the local jvm's including the jvm for the application running this code

 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gaurav Purandare wrote:
the above code gives you the list of all the local jvm's including the jvm for the application running this code


As VirtualMachine is not part of the standard Java API, it would be useful if you said where you got it from to save people having to search for it.
 
Gaurav Purandare
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joanne Neal wrote:
As VirtualMachine is not part of the standard Java API, it would be useful if you said where you got it from to save people having to search for it.




sorry,..the code from java Attach API

I thought i had mentioned the api's name in my previous post
 
Gaurav Purandare
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
\Java\jdk..\lib\tools.jar

You can get the package in the above jar
the jar file is distributed with jdk's its present in lib folder
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic