打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
JDK默认内存大小查看方法总结
userphoto

2013.05.09

关注
总之有如下的方法.
1. linux下使用 java -XX:+PrintFlagsFinal -version 2>&1 | grep MaxHeapSize
windows下使用 java -XX:+PrintFlagsFinal -version |findstr MaxHeapSize
2. 使用jconsole连接后查看
3.  Runtime.getRuntime().maxMemory();
What is the default maximum heap size for Sun's JVM from Java SE 6?
18favorite6
What is the default maximum heap size for Sun's JVM from Java SE 6 (i.e. equivalent to setting -Xmx)?
Looks like for Java SE 5 with a server-class machine, it's
Smaller of 1/4th of the physical memory or 1GB.
Bonus question: Looks like for IBM's JVM you can ask it
java -verbose:sizes -versionCan you similarly ask Sun's JVM?
Edit:
I used Runtime.getRuntime().maxMemory to confirm min(physical memory/4, 1G), referenced in Sun documentation.
java jvm memory-management
share|improve this question
edited Aug 23 '12 at 6:56
community wiki
4 revs, 2 users 94%dfrankow
Why is this community wiki? Do you expect that it should lead to a lot of discussion? – danben May 26 '10 at 17:27
I don't really know when community wiki is valuable, so it was an experiment. – dfrankow May 27 '10 at 13:19
5 Answers
activeoldestvotes
25accepted
java 1.6.0_21 or later, or so...
$ java -XX:+PrintFlagsFinal -version 2>&1 | grep MaxHeapSizeuintx MaxHeapSize := 12660904960 {product}It looks like the min(1G) has been removed.
share|improve this answer
answered Feb 9 '12 at 23:10
community wiki
qmc
8
One can ask with some Java code:
long maxBytes = Runtime.getRuntime().maxMemory();System.out.println("Max memory: " + maxBytes / 1024 / 1024 + "M");See javadoc.
share|improve this answer
answered May 27 '10 at 13:25
community wiki
dfrankow
4
one way is if you have a jdk installed , in bin folder there is a utility called jconsole(even visualvm can be used). Launch it and connect to the relevant java process and you can see what are the heap size settings set and many other details
When running headless or cli only, jConsole can be used over lan, if you specify a port to connect on when starting the service in question.
share|improve this answer
edited Aug 24 '11 at 16:44
community wiki
Inv3r53
it is headless, so no graphics capabilities. – dfrankow May 27 '10 at 13:19
2
With JDK, You can also use jinfo to connect to the JVM and get the value for MaxHeapSize:
jinfo -flag MaxHeapSize
share|improve this answer
edited Oct 18 '12 at 2:21
community wiki
2 revs, 2 users 75%user1754962
0
As of JDK6U18 following are configurations for the Heap Size.
In the Client JVM, the default Java heap configuration has been modified to improve the performance of today's rich client applications. Initial and maximum heap sizes are larger and settings related to generational garbage collection are better tuned.
The default maximum heap size is half of the physical memory up to a physical memory size of 192 megabytes and otherwise one fourth of the physical memory up to a physical memory size of 1 gigabyte. For example, if your machine has 128 megabytes of physical memory, then the maximum heap size is 64 megabytes, and greater than or equal to 1 gigabyte of physical memory results in a maximum heap size of 256 megabytes. The maximum heap size is not actually used by the JVM unless your program creates enough objects to require it. A much smaller amount, termed the initial heap size, is allocated during JVM initialization. This amount is at least 8 megabytes and otherwise 1/64 of physical memory up to a physical memory size of 1 gigabyte.
Source : http://www.oracle.com/technetwork/java/javase/6u18-142093.html
share|improve this answer
answered Mar 29 at 7:52
community wiki
Jābir
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
JAVA Memory Concept
JVM优化配置(转)
在 JNI 编程中避免内存泄漏
jmap命令(Java Memory Map)
4 Reasons Why Data Engineers Don't Use Cassandra
大数据IMF传奇行动绝密课程第51课:Spark性能优化第七季
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服