Adjusting heap memory

Help
Adrian
2007-01-12
2013-05-23
  • Adrian

    Adrian - 2007-01-12

    Hi,

    I love one-jar and I'm using it on my current project. One problem I would like to circumvent is that I would like the user not to have to worry about setting memory and using a command line interface to increase the heap space.

    eg.

    java -jar -mx512M one-jar.jar

    Instead I'd like to control this from within one-jar. Is it possible to do this?

    Basically I want to preserve the 'double click' experience and still have the flexibility of increasing Java heap space.

    Regards,

    Adrian

     
    • Joe Nasca

      Joe Nasca - 2008-07-26

      Hi Adrian,<br/>
      Firstly, you <i>should</i> be using an install script to generate a shortcut to the jar.  The shortcut's target string will include the VM heap arguments.
      <br/>
      But there is a way workaround: you can recursively execute your program via calls to Process.exec(), attempting to apply the -Xmx (max heap size) argument at each call, but decrementing by some static amount before the call.
      <br/>
      There is a post on the Sun forums which works OK but you might want to tidy it up for your specific implementation:
      http://forums.sun.com/thread.jspa?messageID=9482026

       

Log in to post a comment.