This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes code to find available jvm's Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "code to find available jvm Watch "code to find available jvm New topic
Author

code to find available jvm's

Anuj Troy
Ranch Hand

Joined: Apr 07, 2005
Posts: 30
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.


SCJP 1.4, SCWCD 1.4
your eyes cannot see what your mind does not know
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

What have you tried so far?


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Anuj Troy
Ranch Hand

Joined: Apr 07, 2005
Posts: 30
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30130
    
150

You mean like JMX?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Anuj Troy
Ranch Hand

Joined: Apr 07, 2005
Posts: 30
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

Joined: Jun 24, 2003
Posts: 3274
    
    5

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

Joined: Apr 06, 2009
Posts: 19
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


Gaurav
James Basller
Ranch Hand

Joined: Sep 07, 2008
Posts: 58
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

Joined: Apr 06, 2009
Posts: 19

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

Joined: Aug 05, 2005
Posts: 3432
    
  12
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.


Joanne
Gaurav Purandare
Greenhorn

Joined: Apr 06, 2009
Posts: 19
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

Joined: Apr 06, 2009
Posts: 19
\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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: code to find available jvm's
 
Similar Threads
two JVM under one Processor
BufferedReader input file size limit
does gc return memory to operation system?
stack and heap?
verbose:gc