gpt4 book ai didi

java - Tomcat使用哪些内存类型,如何控制

转载 作者:行者123 更新时间:2023-11-28 22:15:16 24 4
gpt4 key购买 nike

我知道 Tomcat 在运行时使用了几种内存类型。

我唯一用过的——java堆。它可以通过 JAVA_OPTS env 属性来控制,比如 '-Xmx128M -Xms64M'

我发现还有 -XX:MaxPermSize、-XX:MaxNewSize 等。

我问的原因是我试图在 200Mb RAM 内存(它是 VPS 服务器)上启动 Tomcat5.5。我已经使用“-Xmx128M -Xms64M”设置了 Java 堆大小,但似乎从启动开始它就消耗了更多(如果可以启动的话。有时启动会立即失败并出现 OutOfMemoryException),没有部署任何应用程序

值得注意的是,如果我启动 maven 的 tomcat 插件,它工作得很好。只有单独的 tomcat 因内存而失败。

提前感谢您的想法。

最佳答案

如您所说,堆内存只是 JVM 的内存池之一,还有其他内存池。

阅读本文以了解它们是什么、如何控制它们以及如何监控它们:

http://java.sun.com/j2se/1.5.0/docs/guide/management/jconsole.html

Heap and Non-heap Memory

The JVM manages two kinds of memory: heap and non-heap memory, both created when it starts.

Heap memory is the runtime data area from which the JVM allocates memory for all class instances and arrays. The heap may be of a fixed or variable size. The garbage collector is an automatic memory management system that reclaims heap memory for objects.

Non-heap memory includes a method area shared among all threads and memory required for the internal processing or optimization for the JVM. It stores per-class structures such as a runtime constant pool, field and method data, and the code for methods and constructors. The method area is logically part of the heap but, depending on implementation, a JVM may not garbage collect or compact it. Like the heap, the method area may be of fixed or variable size. The memory for the method area does not need to be contiguous.

In addition to the method area, a JVM implementation may require memory for internal processing or optimization which also belongs to non-heap memory. For example, the JIT compiler requires memory for storing the native machine code translated from the JVM code for high performance.

关于java - Tomcat使用哪些内存类型,如何控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1193321/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com