为JVM启动内存分配 [英] Starting memory allocation for JVM

查看:131
本文介绍了为JVM启动内存分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始在 java 命令上使用 -Xmx 选项,以允许我的进程使用一点点更多的内存(256Mb,虽然我认为我目前使用的内存不到128Mb)。我还注意到启动内存的 -Xms 选项,默认值为2Mb。我该怎么设置这个值以及为什么?

I'm beginning use the -Xmx option on the java command to allow my processes to use a little more memory (256Mb, though I think I'm currently using less than 128Mb). I've also noticed the -Xms option for starting memory, with a default value of 2Mb. What should I set this value to and why?


参考:Java


推荐答案

-Xmx 参数定义了堆可以达到的最大内存大小JVM。您必须很好地了解您的程序并查看它在负载下的执行情况并相应地设置此参数。如果程序的堆内存达到最大堆大小,则较低的值可能会导致 OutOfMemoryException 或性能非常差。如果您的程序在专用服务器上运行,您可以将此参数设置得更高,因为它不会影响其他程序。

The -Xmx argument defines the max memory size that the heap can reach for the JVM. You must know your program well and see how it performs under load and set this parameter accordingly. A low value can cause an OutOfMemoryException or very poor performance if your program's heap memory is reaching the maximum heap size. If your program is running on a dedicated server you can set this parameter higher because it wont affect other programs.

-Xms 参数设置JVM的初始和最小堆内存大小。这意味着当您启动程序时,JVM将立即分配此数量的内存。如果您的程序从一开始就消耗大量的堆内存,这非常有用。这避免了JVM需要定期增加堆大小,因此您可以在那里获得一些性能。如果您不知道此参数是否对您有所帮助,请不要使用它。

The -Xms argument sets the initial and minimum heap memory size for the JVM. This means that when you start your program the JVM will allocate this amount of memory instantly. This is useful if your program will consume a large amount of heap memory right from the start. This avoids the JVM needing to regularly increase the heap size and so you can gain some performance there. If you don't know if this parameter is going to help you, don't use it.

使用Resin等服务器端Java应用程序进行设置是一种很好的做法。最小 -Xms 和最大 -Xmx 堆大小为相同的值。
您可以设置为256或512Mb。

It is good practice with server-side Java applications like Resin to set the minimum -Xms and maximum -Xmx heap sizes to the same value. You can set to 256 or 512Mb.

这篇关于为JVM启动内存分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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