通过System.setProperty设置内存没有什么影响? [英] How there is no affect of setting memory through System.setProperty?

查看:439
本文介绍了通过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.javaws.jre.0.args=-Xmx512m.But in both case i am getting the result 259522560

推荐答案

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

The JVM memory parameters for a Hotspot Java implementation can only be set via the command line options when the JVM is launched / started. Setting them in the system properties either before or after the JVM is launched will have no effect.

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

What you are trying to do simply won't work.

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

By the time any Java code is able to run, it is too late to change the heap size settings. It is the same whether you run your code using the java command, using web start, using an applet runner, using an embedded JVM in a browser ... or any other means.

这篇关于通过System.setProperty设置内存没有什么影响?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆