How can I let the user easily choose how much memory will be allocated in a Java Swing application?

We have a Swing application that processes relatively large amounts of data. For example, we are currently processing CSV files with millions of rows of data. For reasons of performance and simplicity, we simply store all the data in memory. However, different users will have different amounts of data that they need to process, as well as different amounts of RAM. When creating the installer, of course, we need to specify the size of the heap. Is there an easy way to let the user specify the heap without having to manually edit the configuration or the .bat file? I assume that not all users will be happy with this.

I saw one example in which the application indicated three different shortcuts, each of which has a different amount of memory. This might work, but I would like the option to be more flexible. Then the user can choose the one that is best for them.

+3
source share
5 answers

I recommend having something similar to IntelliJ. It raises a configuration dialog when an OutOfMemoryException is thrown. This dialog box allows the user to adjust the size of the heap and saves it to idea.exe.vmoptions. You will need to add the contents of the file to the java / javaw launch command or have one boot program for Java and run the real one.

, . , , , , .

, OutOfMemoryExceptions , !

+6

startup.jar , script. startup.jar Runtime.exec() .

2 JVM, , JVM. , JVM .

+1

:

  • script, :
@echo off
setlocal
REM This reads the JVM command line options from a user configuration file
for /f %x in (%HOMEDRIVE%%HOMEPATH%\myapp.config) do set JVM_OPTIONS=%x
REM Important: call javaw and not java
javaw -jar myApp.jar %JVM_OPTIONS%
endlocal
  • Swing .... , , , . , ( -Xmx) , - , .
+1

outofmemory excpetion, lauch, swing, , , Runtime.exec() , java -cp lib jar vmoptions, jvm , user.sample:

 Runtime.getRuntime().exec("java -cp
 -Xms2560m -Xmx2560m -XX:NewSize=32M -XX:MaxPermSize=256M -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+UseParNewG launch.jar");
+1

, . , NSIS. , eclipse. nsi, , .

As for your current requirement, simply add the page to the installer for the parameters and, based on the option selected, copy the correct system properties file to the user settings folder, which you can use to start your program. I'm not sure if this is possible, but I think that after installing the program, the user can restart the installer and select another option.

0
source

Source: https://habr.com/ru/post/1763977/


All Articles