java支持的最大内存
程序员文章站
2022-07-14 18:35:49
...
1、jdk各个版本在不同操作系统中支持的最大内存是不一样的,但是可以通过以下方法来进行测试。
c:>java -Xmxxxxxm(g) -version
其中xxxx为最大内存数值, m(g)是内存的计量单位,如果命令能够正确显示出jdk的版本等信息,说明当前jdk支持测试的最大内存数量,否则说明测试的内存超出了jdk支持的最大值,
例如:
c:\\documents and settings\\fengbaoxp>java -xmx1g -version
java version \"1.6.0_03\"
java(tm) se runtime environment (build 1.6.0_03-b05)
java hotspot(tm) client vm (build 1.6.0_03-b05, mixed mode)
命令正确显示了jdk信息,说明当前jdk能够支持1g的内存。
c:\\documents and settings\\fengbaoxp>java -xmx2g -version
error occurred during initialization of vm
could not reserve enough space for object heap
could not create the java virtual machine.
-bash-3.00$ ./java -Xmx2048m -version
java version "1.6.0_04"
Java(TM) SE Runtime Environment (build 1.6.0_04-b12)
Java HotSpot(TM) Server VM (build 10.0-b19, mixed mode)
-bash-3.00$ ./java -Xmx1024m -version
java version "1.6.0_04"
Java(TM) SE Runtime Environment (build 1.6.0_04-b12)
Java HotSpot(TM) Server VM (build 10.0-b19, mixed mode)
-bash-3.00$ ./java -Xmx4096m -version
Invalid maximum heap size: -Xmx4096m
The specified size exceeds the maximum representable size.
Could not create the Java virtual machine.
命令打印出错误信息,说明当前jdk不能支持2g的内存。
2、jre还区分client和server两个版本
client版本加载速度较快,但是支持内存比server要少,比较适合桌面应用;
server版本加载速度较慢,但是运行比较快而且稳定,一些jre还针对server版进行优化,所以我们运行服务端程序最好使用server版。
c:\\documents and settings\\fengbaoxp>java -version
java version \"1.6.0_03\"
java(tm) se runtime environment (build 1.6.0_03-b05)
java hotspot(tm) client vm (build 1.6.0_03-b05, mixed mode, sharing)
说明当前jre为client版
c:\\documents and settings\\fengbaoxp>java -version
java version \"1.6.0_03\"
java(tm) se runtime environment (build 1.6.0_03-b05)
java hotspot(tm) server vm (build 1.6.0_03-b05, mixed mode)
说明当前jre为server版
jdk一般默认为client版,要想修改为server版,需要修改 [jre安装目录]/lib/i386/jvm.cfg文件
将:
-client known
-server known
调整顺序改为:
-server known
-client known
PS:姥姥滴,现在才知道jre还分客户端和服务器端的,这个估计好多公司的基本都不知道吧!
c:>java -Xmxxxxxm(g) -version
其中xxxx为最大内存数值, m(g)是内存的计量单位,如果命令能够正确显示出jdk的版本等信息,说明当前jdk支持测试的最大内存数量,否则说明测试的内存超出了jdk支持的最大值,
例如:
c:\\documents and settings\\fengbaoxp>java -xmx1g -version
java version \"1.6.0_03\"
java(tm) se runtime environment (build 1.6.0_03-b05)
java hotspot(tm) client vm (build 1.6.0_03-b05, mixed mode)
命令正确显示了jdk信息,说明当前jdk能够支持1g的内存。
c:\\documents and settings\\fengbaoxp>java -xmx2g -version
error occurred during initialization of vm
could not reserve enough space for object heap
could not create the java virtual machine.
-bash-3.00$ ./java -Xmx2048m -version
java version "1.6.0_04"
Java(TM) SE Runtime Environment (build 1.6.0_04-b12)
Java HotSpot(TM) Server VM (build 10.0-b19, mixed mode)
-bash-3.00$ ./java -Xmx1024m -version
java version "1.6.0_04"
Java(TM) SE Runtime Environment (build 1.6.0_04-b12)
Java HotSpot(TM) Server VM (build 10.0-b19, mixed mode)
-bash-3.00$ ./java -Xmx4096m -version
Invalid maximum heap size: -Xmx4096m
The specified size exceeds the maximum representable size.
Could not create the Java virtual machine.
命令打印出错误信息,说明当前jdk不能支持2g的内存。
2、jre还区分client和server两个版本
client版本加载速度较快,但是支持内存比server要少,比较适合桌面应用;
server版本加载速度较慢,但是运行比较快而且稳定,一些jre还针对server版进行优化,所以我们运行服务端程序最好使用server版。
c:\\documents and settings\\fengbaoxp>java -version
java version \"1.6.0_03\"
java(tm) se runtime environment (build 1.6.0_03-b05)
java hotspot(tm) client vm (build 1.6.0_03-b05, mixed mode, sharing)
说明当前jre为client版
c:\\documents and settings\\fengbaoxp>java -version
java version \"1.6.0_03\"
java(tm) se runtime environment (build 1.6.0_03-b05)
java hotspot(tm) server vm (build 1.6.0_03-b05, mixed mode)
说明当前jre为server版
jdk一般默认为client版,要想修改为server版,需要修改 [jre安装目录]/lib/i386/jvm.cfg文件
将:
-client known
-server known
调整顺序改为:
-server known
-client known
PS:姥姥滴,现在才知道jre还分客户端和服务器端的,这个估计好多公司的基本都不知道吧!