Getting JVM Heap Size

I am trying to find ways to the current Heap size of a JVM

For example if the max jvm size is 100 MB, I want a shell script or a java program or C program to check the HEAP size used by the JVM at any given point of time. I have searched the whole internet I could not find anything useful. If anyone can help me that should be great.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:
not sure there is a way from outside the jvm
see here for getting it within the jvm
Mick BarryJava DeveloperCommented:
and it would depend on the vm's being used
You can get that info from outside the vm using jmap. See
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

HonorGodSoftware EngineerCommented:
You mean the current heap utilization, or the maxHeapSize value?

If you mean that you want to analyze the heap utilization, you're going to have to use the PMI, as discussed here:

If you want to get the maxHeapSize, that is much easier, e.g., something like this:
# This only works for an unManaged Server.
server = AdminConfig.list( 'Server' );
node   = AdminControl.getNode();
mHS    = AdminTask.showJVMProperties('[-serverName %s -nodeName %S -propertyName maximumHeapSize]' % ( server, node ) )
print 'Max Heap Size for server %s on node %s is %s' % ( server, node, mHS );

Open in new window

madhuthetomAuthor Commented:
HI thanks a lot for the idea.

But I Dont want to get the heap size for WAS server . I need to do it for websphere message broker
Borker does not expose any it has to be done only in shell script or C or java
HonorGodSoftware EngineerCommented:
Isn't message broker a WebSphere Application Server application?

What version of Message Broker are you using?

madhuthetomAuthor Commented:
I am using WMB 6.1
Please read about Java's Profiling (& related protocols), this could be done easily.
1. Are you looking to report the jvm (min /max) parameters being set for an exgrp?

This can be obtained by mqsireportproperties command
mqsireportproperties BrokerName -e ExgrpName -o ComIbmJVMManager -a


2. Are you looking for JVM running within the biphttplistener process

I think there is no mqsiproperties to report the value, but the default value is 192MB.

To change the value,modify the message broker registry.


Under the registry key HKEY_LOCAL_MACHINE\SOFTWARE\IBM\WebSphereMQIntegrator\2\<BrokerName>\CurrentVersion create a new String value named MaxJVMHeapSize. Set this new String value to the JVM maximum heap size required in bytes. For example: 536870912 for 512 MB.


In the directory <Broker File Path>/<Broker Name>/CurrentVersion/, create a new file named MaxJVMHeapSize. Set the contents of this file to the JVM maximum heap size required in bytes. For example: 536870912 for 512 MB.

For the changes to take affect, you will to stop and restart Message Broker.


3) If you are  looking for value of heap size occupied by exgrp jvm at a given point

 a)you can explore JVM  profiling as explained by Guneshraj.

 b) set the following in broker profile  
export MQSIJVERBOSE=-verbose:gc
This way, broker publishes an xml msg with details of exgrp jvm.
 it only publishes only when the exgrp starts up, not after that (ie: not periodically or so..)

HonorGodSoftware EngineerCommented:
Based upon the original question, http://#a24831034 appears to provide the most accurate answer to it.
Based on author requirement the answer for the question is ID: 24834206.
madhuthetomAuthor Commented:
I dont agree, Thats not what I watned. I have found the solution

I created a java compute node using to determine the help size, once it goes to 90% usage or more and sustains in high utilization for a while, I spin off another JVM instance.

But thanks to all for the help

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java App Servers

From novice to tech pro — start learning today.