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.
            Asked
            
        
        
            Active
            
        
            Viewed 186 times
        
    1
            
            
        - 
                    "*We need to...*" Is this homework then? If so, please tag it as such. – user1329572 Jun 27 '12 at 18:11
 - 
                    1The answer is no. See http://stackoverflow.com/questions/763295/setting-jvm-heap-size-at-runtime. – Aleksander Blomskøld Jun 27 '12 at 18:12
 - 
                    We means me and my team and it is not homework.. i need to set these environment variables from application GUI. – ajkush Jun 28 '12 at 05:41
 
2 Answers
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