How to increase java heap size programmatically

前端 未结 5 1726
抹茶落季
抹茶落季 2020-12-04 01:18

I have a java desktop application for searching files and it is usually reaching the default heap limit pretty soon. I wont have access to all the systems it will be install

相关标签:
5条回答
  • 2020-12-04 02:04

    Setting -Xmx to one gig doesn't mean that the JVM will allocate that much memory upon start-up. The JVM will allocate only -Xms (plus overhead) until more heap space is needed. Do you need to protect your users from thrashing virtual memory or a failed memory allocation from the OS? If not, just set Xmx to a large value. Note that Windows 32bit JVMs will often ignore Xmx settings greater than 1.2Gig, so it's best to not request more than a gig or so to be safe.

    0 讨论(0)
  • 2020-12-04 02:10

    See this post about increase java heap size :

    increase the java heap size permanently?

    Maybe also you could clean some part of your code to reduce memory usage.

    Best Regards

    0 讨论(0)
  • 2020-12-04 02:12

    There is no such standard API to do so.

    I would suggest you use Java Web Start to invoke your application (can be used for local applications to in the latest Sun Java 6) as it allows you to specify values for this.

    You can then have three or four links each pointing to exactly the same files but with "Tiny", "Medium", "Large", "Gigantic" heap sizes.

    0 讨论(0)
  • 2020-12-04 02:14

    Take a look at something like launch4j and consider deploying executables where you can control the limit when someone begins the run of your application.

    You won't be able to do this programmatically.

    0 讨论(0)
  • 2020-12-04 02:17

    For desktop applications, I suggest providing a launcher which can then specify your desired memory size. In addition to configuration of your JVM, you can also provide an icon, file associations, etc.

    See this SO question for deployment alternatives.

    0 讨论(0)
提交回复
热议问题