繁体   English   中英

通过System.setProperty设置内存没有什么影响?

[英]How there is no affect of setting memory through System.setProperty?

import java.io.*;
import java.util.*;
public class ReadPropertiesFile {       
    public static void main(String[] args)throws Throwable{                
        Properties prop = new Properties();                
        prop.load(new FileInputStream(
            "C:\\Windows\\Sun\\Java\\Deployment\\deployment.properties"));
        String Xmx = prop.getProperty("deployment.javaws.jre.0.args",
                                      "This is Default"); 
        if(Xmx!="This is Default")
        {
            System.setProperty("javaplugin.vm.options","\"Xmx\"");
        }
        long maxMemory = Runtime.getRuntime().maxMemory();
        System.out.println("JVM maxMemory also equals to maximum heap size of JVM: "
                                         + maxMemory);
    }
}

当在deployment.properties AND 512MB没有指定任何内容时,它应该maxMemory around 96MB(for 2 gb RAM)打印maxMemory around 96MB(for 2 gb RAM)的值, maxMemory around 96MB(for 2 gb RAM)明确提及deployment.javaws.jre.0.args=-Xmx512m.But in both case i am getting the result 259522560时指定deployment.properties AND 512MB但是deployment.javaws.jre.0.args=-Xmx512m.But in both case i am getting the result 259522560

启动/启动JVM时,只能通过命令行选项设置Hotspot Java实现的JVM内存参数。 在启动JVM之前或之后在系统属性中设置它们将无效。

您尝试做的事情根本行不通。

任何 Java代码都可以运行时,更改堆大小设置为时已晚 使用java命令,使用Web Start,使用Applet运行程序,使用浏览器中的嵌入式JVM 或其他任何方式来运行代码都是相同的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM