Am I right in thinking that when one specifies VM arguments in an IDE (I’m using NetBeans in this instance), that these arguments are only passed when the code is run through the IDE itself?
Essentially, I’d like to specify that when my program runs, the VM’s minimum/initial heap size is 2Gb. I can do this using the -Xms2048m command, but I’m wondering if there’s some way to achieve this without having to type a command (for the customer’s sake).
Even thought I set the VM argument in NetBeans, and Launch4J (I wrap the JAR into an EXE file), when the program boots & outputs the Runtime’s total memory size, it always gives ~120Mb.
What am I missing?
Edit: I output the total memory size using…
int mb = 1024 * 1024; System.out.println("Max Memory: " + Runtime.getRuntime().totalMemory() / mb);
Edit 2: Could one not create a initialising program that takes no arguments, but starts the main program with the relevant VM arguments? Something like…
public class Main { public static void main(String[] args) { String execName = new File(new File("").getAbsolutePath()) + "\Program.exe"; Runtime rt = Runtime.getRuntime(); rt.exec("java -Xms2048m -Xmx4096m -jar " + execName); } }
Advertisement
Answer
The only way to do this is to have the program start another copy of the program witht eh heap you want. Note: the end user might not want 2 GB e.g.
If they have 32-bit windows they cannot e.g. if their default is only 120 MB, they most likely have a 32-bit windows client JVM which can’t be 2 GB. If they have 32 GB or more they might want more than 2 GB.
BTW Gb = Giga-bit, Mb = Mega-bit, GB = Giga Byte. MB = Mega Byte.