简体   繁体   English

关于内存不足异常

[英]about out of memory Exception

I have used Thread Pool for New IO server design . 我已将线程池用于新IO服务器设计。 I have used newFixedThreadPool as a Executors factory method for thread pool creation. 我已经使用newFixedThreadPool作为执行程序工厂创建线程池的方法。 My server is throwing Exception when i execute my server for 20 to 30 minute . 当我执行服务器20到30分钟时,服务器抛出异常。 how to handle this exception. 如何处理此异常。

java.lang.OutOfMemoryError: Java heap space

Obviously you are using too much memory, so now you need to find out why. 显然您正在使用过多的内存,因此现在您需要找出原因。 Without your source it is very hard to to say what is wrong, but even with source it can be problematic when the program start to become complex. 没有源代码,很难说出问题出在哪里,但是即使有了源代码,当程序开始变得复杂时,也会有问题。

What I have found helpful is to take memory dumps and look at them in tools such as Memory Analyzer (MAT) . 我发现有帮助的是获取内存转储,并在诸如Memory Analyzer(MAT)之类的工具中查看它们。 It can even compare several dumps to see what kind of objects are allocated. 它甚至可以比较几个转储,以查看分配了哪种对象。 When you get an idea of what objects exists which you don't think should be there you can use the tool to see what roots it has (which objects has a reference to it). 当您知道哪些对象不存在时,可以使用该工具查看其具有的根源(哪些对象对其具有引用)。

To get a memory dump form a running java program use jmap -dump:format=b,file=heap.bin and to automatically get a memory dump when your program gets and OutOfMemoryError you can run it with java -XX:+HeapDumpOnOutOfMemoryError failing.java.Program 要从正在运行的Java程序中获取内存转储,请使用jmap -dump:format = b,file = heap.bin,并在程序获取OutOfMemoryError时自动获取内存转储,并且可以使用java -XX:+ HeapDumpOnOutOfMemoryError失败运行它。 java程序

You can defnitely try increasing the HEAP SIZE and check if you are getting the issue. 您可以确定尝试增加“堆大小”,然后检查是否遇到问题。

However, I would prefer you to try profiling your application to find out why your heap size and where the memory is being consumed. 但是,我希望您尝试对应用程序进行性能分析,以找出为什么您的堆大小以及消耗内存的位置。 There are few Profilers available as open source you can try. 您几乎可以尝试使用探查器作为开放源代码。

normally its java -Xms5m -Xmx15m MyApp -Xms set initial Java heap size -Xmx set maximum Java heap size 通常,其java -Xms5m -Xmx15m MyApp -Xms设置初始Java堆大小-Xmx设置最大Java堆大小

and in eclipse under java run configuration as VM argument -Xms128m 并在eclipse下在Java下运行配置为VM参数-Xms128m

-Xmx512m -Xmx512m

-XX:permSize=128M -XX:permSize = 128M

-XX:MaxPermSize=384M -XX:MaxPermSize = 384M

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM