Four Gc-java recovery mechanism (Java garbage Collection)

Source: Internet
Author: User

This is explained by jdk1.8. Jdk1.8 's generation has been removed from the permanent generation, only into the new generation (some are also translated into the younger generation) and the old generation.

Noun Explanation:

System throughput: The ratio of the number of threads used to process transactions by the application to the number of threads used for GC.

Pause time: Pauses processing of the application transaction thread when the GC is in progress.

The JVM runs memory into the Cenozoic and older generations. The Cenozoic consists of an Eden area and two survivor areas.

Personal understanding of the GC process:

The generation of Minor Gc,minor GC in the Eden region through the mark-sweep algorithm (the GC algorithm above), to obtain the surviving object. If the size of the surviving object is smaller than the Survivor area, the surviving object is copied to an idle survivor area, and the other survivor area is emptied (the two survivor zone will always be idle), whereas the surviving objects are copied directly to the old generation. In addition, each new generation of objects has a replication value, when a surviving object reaches a certain threshold, it will also be copied from the Cenozoic to the old generation.

Below we specifically explain the GC collectors. When a GC is made, a thread that pauses the application (marking objects in memory) produces a pause time, which is garbage collected.

The Serial Collector (serial GC): Its command is-XX:+USESERIALGC. Use only one thread for GC, for single-threaded servers, or small applications for small datasets (100M). GC Process

The Parallel Collector (parallel GC): Its command is-XX:+USEPARALLELGC. The default is to use the recycle mechanism, which adjusts the memory size according to the parameters of the field. Its primary goal is to improve system throughput (the ratio of the number of threads used to process transactions by the application to the number of threads used for GC). ), which is similar to a serial GC, the main difference is that it uses multiple threads to perform GC, shortening the pause time. Although it is often considered a garbage collection mechanism that guarantees system throughput, it can also use the-xx:maxgcpausemillis=n parameter to limit the pause time. GC Process

However, the Parallel Collector (parallel GC) generally sets the-xx:maxgcpausemillis parameter, as the system can use the Concurrent Mark Sweep (CMS) if required for the pause time Collector.

The Concurrent Mark Sweep collector (CMS GC): Its command is-XX:+USECONCMARKSWEEPGC. Its main goal is to shorten the pausetime. It is divided into two stages mark–sweep. So it has two pause times, but the time is short. GC Process

Garbage-first Garbage Collector (G1 GC): Its command is-XX:+USEG1GC. This recycling mechanism is used for multicore and large memory servers. It is designed to meet the pause time and also to meet the system throughput . It can be used for both generation and old generation of garbage collection, it also has a large object of memory allocation and collection of special treatment.

Experience:

    1. Set-XMX to limit the maximum memory to prevent the server system from crashing.
    2. After setting the maximum memory, adjust the parameters so that the old generation usage rate is 70%-90%.

In addition, it is not recommended to expend effort to adjust the GC when the following conditions are met:

1. A minor GC is time consuming within 50ms.

The 2.Minor GC cycle is above 10s.

3. A full GC is time consuming within 1s.

The 3.Full GC cycle is more than 10 minutes.

Four Gc-java recovery mechanism (Java garbage Collection)

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.