cancel
Showing results for 
Search instead for 
Did you mean: 

How to print the JVM Heap size on Command prompt

Former Member
0 Kudos

Hi All,

I increased teh JVM Heap size thru command prompt

java -Xms512m -Xmx512m.

But i am not sure this applied or not to my JVM becaz after teh exceution of command it is just givean message usage and Help.

So can you plz guide me how to set the JVM Heap size correctly and any command is there to print the JVM heap Size which we set previously?

or else provide some sample code in java to print the JVM Heap Size.

Regds

Phanikumar

Accepted Solutions (1)

Accepted Solutions (1)

former_member182294
Active Contributor
0 Kudos

Hi Phani,

In Windows environment you need to set the Environment Variable.

Right Click on MyComputer -> Advanced -> Environment Variables

Add the following values:

Variable : JAVA_OPTS

Value : -Xms512m -Xmx512m

If you want to print Heap size value the in command prompt type

> echo %JAVA_OPTS%

Regards

Abhilash

Former Member
0 Kudos

Hi Abhilash,

I did the same by create an ENV variable and set the value like this.

Variable : JAVA_OPTS

Value : -Xms512m -Xmx512m

But when i tried to print the echo %JAVA_OPTS% it is showing the

-Xms512m -Xmx512m. Then how should we confirm whether it is

set to 512MB or not?

Is it possible to print only 512MB ?

Regds

phanikumar

former_member182294
Active Contributor
0 Kudos

Hi Phani,

What you want to achieve exactly? When you set the environment variable, JVM always considers this options while executing program. Here <b>m</b> means MB only.

Regards

Abhilash

Answers (1)

Answers (1)

Former Member
0 Kudos

If you want to show what memory is available to your application you can use the Runtime class methods.

Ie:

String getMemoryStats()

{

return "Free memory: "Runtime.getRuntime().freeMemory()/1000000" out Of "Runtime.getRuntime().totalMemory()/1000000" MB";

}