• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Increasing JVM Heap size at run time

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I meant class A simply uses class B .
Ayan
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic