我后来用env看了下环境变量,里面有:
JAVA_OPTS=-Xms128m
但是能根据这个就判断JVM参数有效吗?
还有我后来发现了我原来:
当我登陆LINUX时,报错误提示:
bash: -Xmx128m: command not found
这个地方错误的原因了,应该是:
JAVA_OPTS=-Xms128m-Xmx128m
export JAVA_OPTS
这里不能有空格,加了空格可能是认为第二条命令。。
此时用env查看环境变量,可以观察到:
JAVA_OPTS=-Xms128m-Xmx128m
疑问类似与上面。。。。
根据JDK的文挡:
totalMemory
public long totalMemory()Returns the total amount of memory in the Java Virtual Machine. The value returned by this method may vary over time, depending on the host environment.
Note that the amount of memory required to hold an object of any given type may be implementation-dependent.
Returns:
the total amount of memory currently available for current and future objects, measured in bytes.
但是我运行:out.println("total memory is: " + java.lang.Runtime.getRuntime().totalMemory() / 1024 );
的结果确是
total memory is: 22400 或12400
总是得不到理想的数字,所以我不能很确定通过我上面的方法是否已经有效的设置了JVM参数?