Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Increasing JVM Heap size at run time

 
Ayan Dutta
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15484
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ayan Dutta
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I meant class A simply uses class B .
Ayan
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15484
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic