Java.lang.OutOfMemoryError:Java heap Space Errors and methods (set, GO)

Source: Internet
Author: User
Tags log log xms

The wrong way to resolve the overflow below the heap space is to look for it from the Internet:

Java.lang.OutOfMemoryError:Java Heap Space
===================================================

An exception occurred when using a Java program to query large amounts of data from a database:
Java.lang.OutOfMemoryError:Java Heap Space


This exception information is thrown when the JVM assumes that 98% of the time is used for GC and that the available Heap size is less than 2%.

The JVM heap setting is the set of memory space that the JVM can provision in the course of executing the Java program.

The JVM automatically sets the value of the heap size on its own when it is started. Its initial space (that is,-XMS) is 1/64 of the physical memory, and the maximum space (-XMX) is 1/4 of the physical memory. Can be set using options such as-XMN-XMS-XMX provided by the JVM.
For example: java-jar-xmn16m-xms64m-xmx128m Myapp.jar

Assuming that the heap size setting is small, in addition to these exception information, you will notice that the program's responsiveness slows down. The GC takes up a lot of other time, and the application is assigned less time to run.

The Heap Size does not exceed 80% of the available physical memory, generally the-XMS and-XMX options are set to the same, and the-XMX value of-xmn is 1/4.
The-XMS-XMN setting of the Heap size does not exceed the size of the physical memory. Otherwise, "Error occurred during initialization of VM Could not reserve enough space for object heap" will be prompted.

==========================================================
After a night of hard work. A file replaces the program with the specified string, but because there are too many HTML files for the full-site program that I want to replace. So eclipse always reports the exception of the Java.lang.OutOfMemoryError:Java heap space after the end of a folder, and then crashes.

I think it must be frequent operation caused too late recovery. So in each cycle after adding a thread.sleep (1000), found or to the folder to die, so 1000 to 5000, or to die there, I think it may not be too late to recover so simple, maybe Sun JVM, it is also possible to not release such a situation.


Then I added a-xmx256m to the start-up, which I was able to do.

Think about it. or the principle of garbage collection is not very understanding, on-line check a bit, found a few good articles.

Http://java.ccidnet.com/art/3539/20060314/476073_1.html
Http://www.pconline.com.cn/pcedu/empolder/gj/java/0509/701281.html


Also: Java heap management-garbage collection mentioned a few points, very good, perhaps can be used as a code-knocking rules:

(1) Do not attempt to assume the time at which garbage collection occurs. All of this is unknown. For example, a temporary object in a method becomes a useless object after the method call is complete. At this point, its memory can be freed.

(2) Some classes are available in Java that deal with garbage collection. and provides a way to forcibly run garbage collection-Call System.GC (), but this is an indeterminate method. Java does not guarantee that each call to the method will be able to start garbage collection, it simply will be issued to the JVM such a request, whether or not actually run garbage collection, everything is an unknown.

(3) Pick a garbage collector that suits you. In general, assume that the system does not have special and demanding performance requirements. The default option to use the JVM. Otherwise, it is possible to consider using a targeted garbage collector, such as an incremental collector that is more suitable for systems with higher real-time requirements. The system has a higher configuration, there are more idle resources. The ability to consider using a parallel tag/purge collector.

(4) The key is also difficult to grasp the problem is the memory leak. Good programming habits and rigorous programming attitude is always the most important, do not let your own a small error caused a large memory leak.

(5) Release the reference of the useless object as soon as possible.


Most program apes use a transient variable to have the reference variable voluntarily set to NULL after exiting the active domain (scope). implies that the garbage collector collects the object, and you must also be aware that the referenced object is listening. Suppose there is. Remove the listener and then assign a null value.

That is, for the frequent application of memory and release memory operations, or control the better, but the System.GC () method does not necessarily apply, it is best to use finallize forced to run or write their own finallize method.

================================================
Tomcat


Encounter Tomcat Error: Java.lang.OutOfMemoryError:Java heap space, and then checked the data. Found a workaround:
If Java runs out of memory, the following error occurs:
Exception in thread "main" Java.lang.OutOfMemoryError:Java heap space
Java heap size can be increased as follows:

Java-xms<initial heap size>-xmx<maximum Heap size>
Defaults is:
java-xms32m-xmx128m

Suppose you use win
/tomcat/bin/catalina.bat Add the following command:
Set java_opts=-xms32m-xmx256m

Let's say you use Unix/linux.
/tomcat/bin/catalina.sh Add the following command:
Java_opts= "-xms32m-xmx256m"


=========================================
Reason:


An exception occurred when using a Java program to query large amounts of data from a database:
Java.lang.OutOfMemoryError:Java Heap Space
This exception information is thrown when the JVM assumes that 98% of the time is used for GC and that the available Heap size is less than 2%.


The JVM heap setting is the set of memory space that the JVM is able to provision during the execution of the Java program. The JVM automatically sets the value of the heap size on its own when it is started. Its initial space (that is,-XMS) is 1/64 of the physical memory. The maximum space (-XMX) is 1/4 of the physical memory.

Can be set using options such as-XMN-XMS-XMX provided by the JVM.
The workaround:
Tomcat_home/bin Catalina.bat (Win) or catalina.sh (Linux) before executing the code plus:
Set java_opts=%java_opts%-xms128m-xmx512m

=============================================================
Eclipse Java.lang.OutOfMemoryError:Java Heap Space Solution
===========================================================
Eclipse Java.lang.OutOfMemoryError:Java Heap Space Solution

Eclipse has a boot parameter to set the JVM size, since Eclipse executes its own JVM, so the JVM size set in Eclipse.ini is not the size of the JVM used to detail a program's execution, regardless of the size of the JVM that the detail program executes.

So how can you set the JVM size of a program (of course, the console does not have this problem.) such as: java-xms256m-xmx1024m classname, so you can set the JVM size of the current program)?

Because the default JVM configuration for a program in Eclipse is:-xms8m-xmx128m. So we need to manually adjust the amount of memory we have to handle. So that there is no memory overflow. The detailed setup method is:

Select the class that is being executed. Click the menu ' run as->open run Dialog ... ', select the (x) =argument tab under the VM Arguments box to enter-xmx512m, save execution OK

=======================================================
Java.lang.OutOfMemoryError:Java Heap space in eclipse

Error 2007-06-12 11:53java.lang.outofmemoryerror:java heap space error

In the Tomcat in Catalina.bat Riga
Set Java_opts=-xms256m-xmx512m-djava.awt.headless=true
256 and 512 each are min and Max memory
In Eclipse, the
Windows->preferences. ->TOMCAT->JVM. ->JVM that text box, add-xms256m-xmx512m
This will do it!

==================================
VM setting method in Eclipse-[]-Tag:java.lang.OutOfMemoryError:Java heap space

Right-click and select Run .... Pop-up forms such as the. Fill in the appropriate memory value in the VM input box.

==================================
In eclipse, the Yellow line is a warning.


Private log log = Logfactory.getlog (addcateaction.class);//small Yellow line on Log.
The yellow line here means that you have defined the private variable log, but it is not practical to this variable.


V.add (o); A small yellow line appears below eclipse to indicate that it is still being referenced?
This refers to the method that the Add method is not recommended.

OutOfMemoryError is not related to suspicious references. It is possible that the loop-created object causes insufficient Java memory.

Specify the memory of the Java Virtual machine using the number of parameters.
java-xms256m-xmx1024m-xx:maxpermsize=256m

========================================================
2. Assume that a memory overflow problem occurs during startup, throwing similar exceptions such as the following:
Java.lang.OutOfMemoryError:Java Heap Space

Can try to:
A. Change the Tomcat/bin/catalina.bat, add for example the following content
Set java_opts=-xms256m-xmx512m-djava.awt.headless=true [-xx:maxpermsize=128m]

B.eclipse->windows->preferences. ->TOMCAT->JVM. ->JVM text box, add-xms256m-xmx512m

C.eclipse->preference->java->instal Jres->edit, added:-xms256m-xmx512m

Reason: The JVM assumes that 98% of the time is used for GC and is available, this exception is thrown when the Heap size is less than 2%.


The JVM heap setting is the set of memory space that the JVM is able to provision during the execution of the Java program. The JVM automatically sets the value of the heap size on its own when it is started, and its initial space (that is,-XMS) is 1/64 of physical memory, and the maximum space (-XMX) is 1/4 of physical memory.
Can be set using options such as-XMN-XMS-XMX provided by the JVM.

The Heap Size does not exceed 80% of the available physical memory, generally the-XMS and-XMX options are set to the same, and the-XMX value of-xmn is 1/4.
The-XMS-XMN setting of the Heap size does not exceed the size of the physical memory. Otherwise, "Error occurred during initialization of VM Could not reserve enough space for object heap" will be prompted.

==================================================================

Reasons for my problem:

Using Spring+hibernate to read large amounts of data from a database, using a singleton pattern of Appcontext Getbean, a large number of entity beans are cached in memory ...

There is still no effective way to mitigate this by increasing the size of the JVM's memory and changing the read mode of the data (for example, just reading the useful information).

Change data read mode:
For example, a Entitybean for example, the following field: ID, name, age, address, description.

The assumptions used in this procedure are only the Bean ID and the name field. So just read these two fields from the database instead of reading the entire bean and the associated bean.

Java.lang.OutOfMemoryError:Java heap Space Errors and methods (set, GO)

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.