5

I have a Java 7 program which launches other Java processes. I would like for memory settings for the original program to be passed along to the child processes.

The processes are launched as follows:

//https://stackoverflow.com/questions/636367/executing-a-java-application-in-a-separate-process
String javaHome = System.getProperty("java.home");
String javaBin = javaHome + File.separator + "bin" + File.separator + "java";
String classpath = System.getProperty("java.class.path");
String className = MyClass.class.getCanonicalName();

ProcessBuilder pb = new ProcessBuilder(javaBin, "-cp", classpath, "-Djava.ext.dirs=" + System.getProperty("java.ext.dirs"), className, arg1, arg2);
logger.debug("Running as {}", new Object[]{pb.command()});

pb.start();

The process works correctly, except in the cases where the program needs it's children to have additional memory.

I've iterated over System.getProperties() to look for any of the memory settings, but none seem present.

Specifically, the three memory configurations I need are -Xms, -Xmx, and -XX:MaxPermSize

  • 1
    possible duplicate of [What is the exact meaning of Runtime.getRuntime().totalMemory() and freeMemory()?](http://stackoverflow.com/questions/3571203/what-is-the-exact-meaning-of-runtime-getruntime-totalmemory-and-freememory) – Andreas Aug 26 '15 at 22:59
  • Would this help? [Getting the parameters of a running JVM](http://stackoverflow.com/questions/5317152/getting-the-parameters-of-a-running-jvm) – Obicere Aug 26 '15 at 22:59

1 Answers1

2

In order to get all JVM parameters including Xmx etc You have to use

    java.lang.management.RuntimeMXBean;

Following example lists all jvm parameters available :

  public void runtimeParameters() {

  RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
  List<String> aList = bean.getInputArguments();
  for (int i = 0; i < aList.size(); i++) {

   System.out.println(aList.get(i));

  } 

}
Sharp Edge
  • 4,144
  • 2
  • 27
  • 41