1

We need to set -Xmax and -Xmin Environment variables manually but i want to set these variables from java code. Is there any way to set these variables with java code.? Thanks.

ajkush
  • 587
  • 2
  • 11
  • 25

2 Answers2

3

Do you need to set these settings from the running Java process? I don't believe that is possible. However, you can set them on a child process from a calling Java program, for example via the ProcessBuilder.

ProcessBuilder pb = new ProcessBuilder("myCommand", "-Xmax", value);
pb.directory(new File("dir"));
Process p = pb.start();
Will
  • 6,601
  • 3
  • 31
  • 42
0

I got this solution for this problem:-

     public static void main(String[] args) {
     Properties prop = new Properties();
     try {
        String path=System.getenv("APPDATA");
          path=path.substring(0,path.lastIndexOf('\\')+1)+"LocalLow\\Sun\\Java\\Deployment\\deployment.properties";
            System.err.println(path);

            prop.load(new FileInputStream(path));
            String jreIndex = null; 
            Enumeration enuKeys = prop.keys();
            while (enuKeys.hasMoreElements()) {
                String key = (String) enuKeys.nextElement();
                String value = prop.getProperty(key);
                if(value.contains("1.6.0_26")){
                    String[] st2 = key.split("\\.");  
                    if(st2.length==5){
                        jreIndex = st2[3];
                    }
                }
            }
            //SystemSettings SysConfigsettings = new SystemSettings();
            if(jreIndex != null){
            //  if (SysConfigsettings.getValue(SystemSettings.JRE_HEAP_SIZE))
              {
                prop.setProperty("deployment.javaws.jre."+jreIndex+".args", "-Xmx1024m");
              }
            }
            prop.store(new FileOutputStream(path), "UpdatedHeapSize");
            System.out.println("First : "+prop.getProperty("deployment.javaws.jre.0.args"));
    } catch (Exception e) {
        e.printStackTrace();
    }

}

ajkush
  • 587
  • 2
  • 11
  • 25