Link to home
Start Free TrialLog in
Avatar of lomidien
lomidien

asked on

Increasing Allocated Memory

If I am distributing an executable jar file, is it possible to increase the amount of memory given to the JVM on startup?  Something similar to the following code:

java -Xm256m -Xmx256m myClass"

Thanks,
David
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

I think you may have to provide that in a batch file to start the jar
Avatar of lomidien
lomidien

ASKER

I was afraid of that...bad thing is that I was wanting to deploy via web start.
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I had the same problem when I had to provide a JAVA
 application that had to run on several machines and to a limit of 1Gb of memory.
I gave instructions on how to change the Registry entry for .jar files shell commands,
but later I decided to write a little static method that matches the applications needs to
the numbers at startup (usually 2Mb allocated, 64Mb limit).
If the needs exceed the actual situation it finds out on which version of JAVA it runs
and where its .jar file is.
On success it simply spawns itself with the corrent JVM, parameters as above and commandline.
This even remarkably speeds up: there is already a (tiny) JVM in memory.
If you are interested I can isolate the code for you.

;JOOP!
sciuriware,

That would be fantastic.  It sounds like a solution to my situation.  If you could dig that code up, I would greatly appreciate it.

Thanks,
David
Why would that be necessary if there is already an option in webstart to set the memory parameters?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Works perfectly.  Thanks!
!? Please explain why sciuriware got the *entire* points for posting what, by his own admission, is wheel reinvention
CEHJ,

Just came back to see this.  Actually tried splitting the points and couldn't get it to take.

Thanks,
David
Well you can always reopen it ;-) I'll send a mod over
My solution works for any JAVA program started from any place, by a service, at reboot or even remote.
You can 't call this re-inventing the wheel.
;JOOP!
>>You can 't call this re-inventing the wheel.

It's reinventing the wheel in that there is already a configuration parameter in Webstart to set the heap size
Does it work in all those other cases?

;JOOP!
It's not being used in all those other cases - it's being used in conjunction with Java Webstart
sciuriware,


I am also in need of that code. I have tested ur code. But I do not understand how to include with in classes.

1. When I execute this I use Java.exe as Runtime JVM whereas ur application takes javaw as runtime JVM. May I know the reason for this
2. When I tested this I am not getting anythig printed on screen. Is my perception of understanding that code is wrong??
Please clarify me

Thanks
Sudhakar



             public static void main(String[] argv) throws Throwable
          {
             
                new NeedMemory().needMemory(400, argv); // 400Mb limit, 200Mb initial.
                        System.err.println("Hello There");
                        StringBuffer sb=new StringBuffer("Hello World ");
                        try
                    {
                        while(true)
                    {
                              sb.append(sb.toString());
                                                  System.err.println(sb.length());
                    }
                    }
                    catch(Throwable e)
                    {
                          System.err.println(sb.length());
                    }
                    System.err.println(sb.length());
              }





As the points I got for answering this question have been cancelled, you may ask that (anew) question.
;JOOP!
I'm increasing the points and then splitting, how about that.  :)
Great, you are a true customer.
Btw.: the EE home states: experts are competing for your points; I hope you didn't read "fighting" for your points.
Nevertheless, some answers will be accepted or rejected without understanding of the expert.
Because experts here only "understand" JAVA, not the psychology of programmers.
;JOOP!
sudhakar_koundinya, you may ask a 21 points question for that.
;JOOP!
Ok sciuriware,

https://www.experts-exchange.com/questions/21124914/Increasing-Allocated-Memory.html

can you please answer for my queries at above thread??

Thanks
Sudhakar
:-)

And sciuriware's code (if it's good - and i've no reason to think otherwise) will be excellent where a tight coupling is required between memory controller and 'controllee' and there is no existing method