- e.printStackTrace();
- }
- // System.exit(0);
-
- }
-
- public static long getPhysicalMemory()
- {
- final OperatingSystemMXBean o = ManagementFactory
- .getOperatingSystemMXBean();
-
- try
- {
- if (o instanceof com.sun.management.OperatingSystemMXBean)
+ if (e.getMessage().toLowerCase().contains("memory"))
+ {
+ System.out.println("Caught a memory exception: " + e.getMessage());
+ // Probably the "Cannot allocate memory" error, try without the memory setting
+ ArrayList<String> commandNoMem = new ArrayList<>();
+ for (int i = 0; i < command.size(); i++)
+ {
+ if (!command.get(i).startsWith("-Xmx"))
+ {
+ commandNoMem.add(command.get(i));
+ }
+ }
+ final ProcessBuilder builderNoMem = new ProcessBuilder(
+ commandNoMem);
+ System.out.println("NO MEM COMMAND: "
+ + String.join(" ", builderNoMem.command()));
+ try
+ {
+ builderNoMem.inheritIO();
+ Process processNoMem = builderNoMem.start();
+ processNoMem.waitFor();
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ else