Java Program Memory Overflow problem reason analysis _java

Source: Internet
Author: User
Tags garbage collection

This paper analyzes the reason of the memory overflow problem of Java program in detail. Share to everyone for your reference. Specifically as follows:

Encountered an online system reported Java.lang.OutOfMemoryError:PermGen space error, need to locate the problem. A long time ago to get this, now really a bit do not remember, but this is really a very interesting question, it is worth a good study. First reaction of course is to add-xx:+printgcdetails parameters to see the specific GC log, but because the program is Tomcat startup, worry about the contents of the package too much bad positioning, since under Windows, so still with the help of visual tools.
Then we take a look at the cause of the error, find an explanation on the internet, said very good, posted over to borrow:
PermGen space is the full name of permanent Generation spaces, refers to the permanent storage area of memory, this memory is mainly by the JVM storage class and meta information, class in the loader will be placed in the PermGen In space, it differs from the heap region of the class instance (Instance), and GC (garbage Collection) does not clean up permgen spaces during the runtime of the main program, so if you have a class in your application, PermGen space errors are most likely to occur when the Web server makes pre compile for JSPs. If your web app uses a large number of third-party jars that are larger than the JVM default size (4M), this error message is generated.
so let's first increase the initial memory size of the PermGen:

Linux at the beginning of the file plus:

Copy Code code as follows:
Java_opts= "-xms1024m-xmx1024m-xx:permsize=256m-xx:maxpermsize=256m"

Under Windows, at the beginning of the Catalina.bat file, add:

Copy Code code as follows:
Set java_opts=-xms1024m-xmx1024m-xx:permsize=256m-xx:maxpermsize=256m

We then use the visual memory-viewing tool to locate specific problems. For JDK6 first choice of course is the tool, the more commonly used jconsole and JVISUALVM (after use found the latter more powerful, because there are rich plug-ins to support). This time again encountered a more bizarre problem, that is, the analysis tool can not find the Tomcat process (after the discovery actually started the JRE, the JDK should be able to).

Since the local do not let company, I can connect remotely, open JMX can be.
As above, add in the java_opts inside the beginning of the or Catalina.bat file

Copy Code code as follows:

Start the program with Netstat to see if the port is open properly to ensure that the remote can connect.
I am lazy here, the authenticate turned off, if you need to set some permissions on the things, more trouble. This setting is on my local PC, but not on the server, what software may be installed to seal the port, so I had to make the same cheap, the port changed to 1000. Open JVISUALVM, click File-> add JMX connection, and then add localhost:1000 to connect.

And so on after the program, observe a period of memory changes, I focus on the situation under the perm, has been stable in the appearance of 94m, running all normal day. May be the previous set perm memory size does not take effect, because the perm default initialization is 16m, the largest is 64m, and the actual amount of consumption is indeed likely to lead to this problem, from the current phenomenon should not be the problem again. If you need to further locate the problem, you can also use Btrace to see where a particular method is called. This allows you to navigate to whether some methods are performing as expected.

I hope this article will help you with your Java programming.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.