Elasticsearch--java Memory Overflow __elasticsearch

Source: Internet
Author: User
summary of common situations and handling of Java memory overflow (java.lang.OutOfMemoryError)

Java.lang.OutOfMemoryError This error I believe most developers have encountered, the reason for this error is mostly for the following reasons: JVM memory is too small, the program is not tight, resulting in too much garbage.

There are several common causes of OutOfMemoryError exceptions: The amount of data that is loaded in memory is too large, such as fetching too much data from the database at one time; a reference to objects in the collection class, which is not emptied after use, so that the JVM cannot be recycled; An object entity in the code that has a dead loop or loop that produces too many duplicates, a bug in the Third-party software used, and a small set of startup parameter memory values;

Common error tips for this error: Tomcat:java.lang.OutOfMemoryError:PermGen space Tomcat:java.lang.OutOfMemoryError:Java Heap Weblogic:root cause of Servletexception java.lang.OutOfMemoryError resin:java.lang.OutOfMemoryError Java: Java.lang.OutOfMemoryError

There are several ways to resolve Java.lang.OutOfMemoryError:

One, increase the memory size of the JVM. Methods are: 1 when executing a class file, you can use java-xmx256m Aa.class to set the maximum memory allowed by the JVM to be 256M when running Aa.class. 2 for the Tomcat container, you can set the memory limits on the JVM at startup. For Tomcat, you can add in Catalina.bat:

Set catalina_opts=-xms128m-xmx256m
Set java_opts=-xms128m-xmx256m

or replace%catalina_opts% and%java_opts% as-xms128m-xmx256m.

3 for the resin container, you can also set memory limits on the JVM at startup. Create a Startup.bat file under the Bin folder, which reads as follows:

@echo off called
"Httpd.exe"  "-xms128m" "-xmx256m"
: End

where "-xms128m" is the minimum memory, "-xmx256m" is the maximum memory.

Second, optimize the procedure, release the rubbish.

Mainly include the avoidance of death cycle, should be released in a timely manner resources: memory, the various connections to the database, to prevent loading too much data at a time. The root cause of Java.lang.OutOfMemoryError is that the program is not robust. Therefore, the only way to fundamentally solve the Java memory overflow is to modify the program, releasing the useless objects in time, freeing up the memory space. Encounter this error time to carefully check the program, hey, once again this problem, later write the program will be more careful. Java code leads to outofmemoryerror error resolution:

The

needs to focus on the following points: Check for dead loops or recursive calls in your code. Check for a recurring cycle to produce a new object entity. Check to see if there is a query in the database query that gets all the data. In general, if you take 100,000 records to memory at a time, it can cause a memory overflow. This problem is more covert, before the line, the data in the database is less, not easy to problem, online, the database more data, a query may cause memory overflow. Therefore, the database query as far as possible in the way of paging query. Check whether the collection objects, such as list, map, and so on are not cleared after use. Collection objects such as List and map always have references to objects so that they cannot be reclaimed by GC.

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: info-contact@alibabacloud.com 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.