[英]can a java EE app use more than MAX heap memory
I checked with following code in my servlet: 我在servlet中检查了以下代码:
int mb = 1024 * 1024;
Runtime runtime = Runtime.getRuntime();
out.write("Used Memory:" + (runtime.totalMemory() - runtime.freeMemory()) / mb);
out.write("Free Memory:" + runtime.freeMemory() / mb);
out.write("Total Memory:" + runtime.totalMemory() / mb);
out.write("Max Memory:" + runtime.maxMemory() / mb);
the output is : 输出为:
Used Memory:10
Free Memory:46
Total Memory:57
Max Memory:57
I want my app not to use more than 64 MB heap? 我希望我的应用程序不使用超过64 MB的堆吗? I want to know - is there any way my app can use more then 64 MB heap...(Max Memory:57) ?
我想知道-我的应用程序有什么方法可以使用超过64 MB的堆...(最大内存:57)? ..will my app throw an
OutOfMemoryException
after 57MB? ..我的应用程序在57MB之后会抛出
OutOfMemoryException
吗?
Default Max Heap size is 64Mo, the only way to get more is to set the max size with this parameter : 默认的最大堆大小为64Mo,获取更多的唯一方法是使用以下参数设置最大大小:
-Xmx256m
While this parameter set the start value : 当此参数设置起始值时:
-Xms128m
Don't forget the "m" at the end which means Megabytes, don't give more start memory than max neither. 不要忘了最后的“ m”表示兆字节,不要给启动内存多于max。 Furthermore, there is no setMaxHeapSize() function if it's what you are looking for.
此外,如果您要查找的是没有setMaxHeapSize()函数。
If you are runnning your servlet inside a tomcat you should try with this : 如果要在Tomcat中运行servlet,则应尝试以下操作:
export CATALINA_OPTS=-Xms16m -Xmx256m;
in startup.bat 在startup.bat中
If your servlet need more than JVM can allow, you will get weird errors when reaching the limit and most of the time a OutOfMemoryException, the Garbage Collector will try to avoid that though so it will crawl a bit before throwing it. 如果您的servlet需要JVM所不能提供的更多资源,则在达到限制时会出现奇怪的错误,并且在大多数情况下会发生OutOfMemoryException,垃圾收集器将尽力避免这种情况,因此它将在抛出之前进行一些爬网。
When you run your application you must also specify the max heap size. 运行应用程序时,还必须指定最大堆大小。
For example if your class name is HelloWorld and if you want to set 512mb the heap size then you have to launch te following command: 例如,如果您的类名是HelloWorld,并且要设置512mb的堆大小,则必须启动以下命令:
java -Xmx512m HelloWorld
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.