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.
-
"We need to..." Is this homework then? If so, please tag it as such.user1329572– user13295722012-06-27 18:11:58 +00:00Commented Jun 27, 2012 at 18:11
-
1The answer is no. See stackoverflow.com/questions/763295/….Aleksander Blomskøld– Aleksander Blomskøld2012-06-27 18:12:44 +00:00Commented 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.ajkush– ajkush2012-06-28 05:41:37 +00:00Commented Jun 28, 2012 at 5:41
Add a comment
|
2 Answers
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();
Comments
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();
}
}