简体   繁体   English

Java EE应用程序可以使用超过MAX堆内存的内存吗

[英]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.

相关问题 Java如何分配比指定堆大小更多的内存 - How come Java can allocate more memory than the specified heap size 如果我需要的内存超过Java堆中的内存,该怎么办? - What can I do if I require more memory than there is on the heap in Java? 内存不足时的Java EE堆转储 - Java EE heap dump on Out of Memory 对于具有专用 memory 的 java 应用程序,最小堆大小低于最大堆大小是否有意义? - For java applications with dedicated memory, does it make sense to have a lower Min Heap Size than Max Heap Size? 堆内存消耗的比承诺内存更多 - Heap memory consumed more than committed memory Java 本机 memory 跟踪堆提交的数量远远超过堆转储的总数 - Java native memory tracking heap committed much more than total from heap dump JVM使用超过最大堆的LOT - JVM using a LOT more than the max Heap 我可以使用压缩oops多于32 GB的堆 - Can i use more heap than 32 GB with compressed oops 运行一些Java应用程序,其总堆大小内存设置为超过phisycal内存 - Running a few java applications with total heap size memory set to more than phisycal memory Java 使用的内存比堆大小(或正确大小的 Docker 内存限制)多得多 - Java using much more memory than heap size (or size correctly Docker memory limit)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM