Running external Java Process with ProcessBuilder and give heap size

365 Views Asked by At

I didn't figured out yet how to run a external Java Application with a specify heap size in a ProcessBuilder.

The ProcessBuilder is just that simple as it should:

ProcessBuilder pb = new ProcessBuilder("java", "-jar", jar);
Process p = pb.start();

But, how can I give the Process a specify heap size. f.E java -jar -Xms1048M -Xmx2048M somejar.jar

Thank you Guys very much :D LG

1

There are 1 best solutions below

0
flaxel On

You can easily add the options when creating the ProcessBuilder:

ProcessBuilder pb = new ProcessBuilder("java", "-jar", "-Xms1048M", "-Xmx2048M", jar);
Process p = pb.start();

You can use a list or a string array containing the program and its arguments, as described in the documentation.