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 Increasing JVM Heap size at run time 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 "Increasing JVM Heap size at run time" Watch "Increasing JVM Heap size at run time" New topic
Author

Increasing JVM Heap size at run time

Ayan Dutta
Ranch Hand

Joined: Oct 16, 2005
Posts: 94
Suppose I have a program A.java which in turn calls B.java.
When I am invoking B.java ,I need to allocate more heap size (using -Xms,-Xmx etc).
Can I do that programmatically while calling B.java from A.java ?

Regards,
Ayan
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

I don't know exactly what you mean by "A.java calls B.java". Source files don't call each other. Do you mean that you have two classes (A and B) and that class A simply uses class B? Or does class A invoke class B in some special way? Please explain.

You can't change the memory settings that you can set with -Xms and -Xmx of the JVM at runtime.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Ayan Dutta
Ranch Hand

Joined: Oct 16, 2005
Posts: 94
I meant class A simply uses class B .
Ayan
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Why do you need to allocate more heap size - do you get an OutOfMemoryError? Why can't you simply add -Xms and -Xmx switches on the command line when you start the program - why do you want to do this programmatically?

If it is because you don't want users to have to think about typing those things in on the command line, then simply provide a batch file or shell script to start your program, that includes the parameters that your program needs.
Ayan Dutta
Ranch Hand

Joined: Oct 16, 2005
Posts: 94
Yes mainly to avoid OutOfMemory error .
The situation is I have a program that was getting OutOfMemory Error .
I was using Eclipse , in the file eclipse.ini I mentioned those
-Xms and -Xmx parametres,but nothing happened.
That is when I am allocating heap -size for entire Eclipse application ,
my specific program is not getting benifitted that much .
But when I am running that program mentioning those -Xms and -Xmx parametres,the prog is running fine .

So ,when I am using that code inside a project I may need to increase the heap size when that particular code will be executed .That is why I want to set the heap size programmatically (If possible).
Regards ,
Ayan Dutta
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
I think heap size cannot be increased on the fly.
Before the JVM starts is should be supplied with the heap size or else it takes the default.


Rahul Bhattacharjee
LinkedIn - Blog
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Increasing JVM Heap size at run time
 
Similar Threads
Using import and static import problem
Question for Mr. Michael Ernest
SCJP chapter 10 : Development Classpath problem
Help! Difficult in compiling Servlets
Package issue