This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
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 ?
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.
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.
Joined: Oct 16, 2005
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