This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Java in General and the fly likes JVM Ram settings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "JVM Ram settings" Watch "JVM Ram settings" New topic
Author

JVM Ram settings

Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

Is there an option or property that will allow me to set the JVMs memory usage ? Can i say to the JVM - "hey ! i am only going to allow you 120MB of ram".


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Rajah Nagur
Ranch Hand

Joined: Nov 06, 2002
Posts: 239
-Xmsn
Specify the initial size, in bytes, of the memory allocation pool. This value must be a multiple of 1024 greater than 1MB. Append the letter k or K to indicate kilobytes, or m or M to indicate megabytes. The default value is 2MB. Examples:

-Xms6291456
-Xms6144k
-Xms6m


-Xmxn
Specify the maximum size, in bytes, of the memory allocation pool. This value must a multiple of 1024 greater than 2MB. Append the letter k or K to indicate kilobytes, or m or M to indicate megabytes. The default value is 64MB. Examples:

-Xmx83886080
-Xmx81920k
-Xmx80m

Check this site


You can't wake a person who is <b><i>pretending</i></b> to be asleep.<br />Like what <b>"it"</b> does not like - <i> Gurdjieff </i>
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14278
    
  21

So John, in your case you want to use this:

java -Xmx120m com.mypackage.MyProgram

Which means that the JVM will not allocate more than 120 MB RAM. If your Java program tries to use more, it will get an OutOfMemoryException.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

Thats cool. I wanted to know if one could set this limit. Now i know.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JVM Ram settings