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.

3
  • "We need to..." Is this homework then? If so, please tag it as such. Commented Jun 27, 2012 at 18:11
  • 1
    The answer is no. See stackoverflow.com/questions/763295/…. Commented Jun 27, 2012 at 18:12
  • We means me and my team and it is not homework.. i need to set these environment variables from application GUI. Commented Jun 28, 2012 at 5:41

2 Answers 2

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();
Sign up to request clarification or add additional context in comments.

Comments

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();
    }

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.