Spring Boot内存消耗增加到超过

编程入门 行业动态 更新时间:2024-10-24 16:23:49
本文介绍了Spring Boot内存消耗增加到超过-Xmx选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我注意到Spring Boot应用程序不遵守通过Xmx选项设置的内存量. 例如:java -Xss64m -Xmx64m -jar test.jar

I noticed Spring Boot application does not obey the amount of memory set via Xmx option. For example: java -Xss64m -Xmx64m -jar test.jar

我还在控制台上打印了启动时应用程序实际使用的内存量,并显示: 最大内存:61M

I also printed on console the amount of memory really used by application at startup, and shows: Max memory: 61M

long maxBytes = Runtime.getRuntime().maxMemory(); System.out.println("Max memory: " + maxBytes / 1024 / 1024 + "M");

当我在访问任何网页之前打开Windows进程时,它显示+ -105M,那么Java怎么说61M?

When I open Windows processes before accessing any web page, it shows +-105M, so how can Java say 61M?

访问任何网页后,它从+ -125M变为+ -135M.为什么会有这样的增加?它应该提供"java.lang.OutOfMemoryError:PermGen空间",但不要以这种方式增加.

After accessing any web page it goes from +-125M to +-135M. Why is there such increase? It should give "java.lang.OutOfMemoryError: PermGen space" but do not increase this way.

如果许多应用程序可能耗尽服务器的内存,这会让我感到担忧.顺便说一句,我正在使用Java 1.8_45

It makes me get worried, if many applications could run out of memory at the server. By the way, I am using Java 1.8_45

推荐答案

在监视Spring Boot应用程序之后,我发现了一些可能的原因,例如:

After monitoring the Spring Boot application, I found out some possible reasons such as:

  • http线程数(Undertow开始于每个线程约50个线程 默认值,但您可以通过属性增加/减少所需的线程数量)
  • 通过JNI访问本机例程(.dll,.so)
  • 静态变量
  • 使用缓存(内存缓存,ehcache等)
  • 如果VM是32位或64位,则64位会使用更多的内存来运行同一应用程序,因此,如果您不需要大于1.5GB的堆,请使应用程序的运行时间保持在32位以上以节省内存.
  • Number of http threads (Undertow starts around 50 threads per default, but you can increase / decrease via property the amount of threads needed)
  • Access to native routines (.dll, .so) via JNI
  • Static variables
  • Use of cache (memcache, ehcache, etc)
  • If a VM is 32 bit or 64 bit, 64 bit uses more memory to run the same application, so if you don't need a heap bigger than 1.5GB, so keep your application runnnig over 32 bit to save memory.
  • 更多推荐

    Spring Boot内存消耗增加到超过

    本文发布于:2023-10-28 08:28:33,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1536095.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:消耗   内存   增加到   Spring   Boot

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!