JAVA Young Generation Collector Section Nineth

Source: Internet
Author: User

JAVA Young Generation Collector Section Nineth

Continuing in the previous chapter, STW is the time when the GC pauses, and he pauses all threads in our program . If the STW takes longer and more times, the stability and usability of our system will be greatly reduced.

So if we need to tune the virtual machine when necessary, one of the main goals of tuning is to reduce the STW time, which is to reduce the number of full GC. So here we analyze the advantages and disadvantages of each collector from the perspective of tuning.

Start with a collector that acts on the young generation (using a Copy collection algorithm):

Serial collector: A single-threaded collector that, when reclaimed, must suspend all other worker threads until the collection is finished. Disadvantage: The user experience is poor because you want to completely pause the thread. But because the new generation recovers faster, there is very little time to pause, and there is no overhead of thread switching, so it is also simple and efficient. Enabled by the-XX:+USESERIALGC parameter.

Parnew Collector: This is a multithreaded version of the serial collector for devices with multicore CPUs. But for a single-core device, there is a need to switch between threads, but the efficiency is not single-threaded high. The-XX:+USEPARNEWGC parameter is enabled by restricting the number of threads collected through the-xx:parallelgcthreads parameter.

Parallel Scavenge Collector: This collector is the default young generation collector for all the examples in our article. His focus is different from other collectors, and the other focus is to shorten the full GC's time as much as possible. The collector is concerned with a manageable throughput. Throughput = time that the code was run/(time +GC the code was run), setting the maximum GC pause time through the parameter -xx:maxgcpausemillis , and -xx:gctimeratio setting the throughput size. The-XX:+USEPARALLELGC parameter is enabled. It is primarily suitable for tasks that operate in the background and do not require too much interaction.

The adaptive adjustment strategy can be turned on by the-xx:+useadaptivesizepolicy parameter, which frees us to set up some of the details of the heap memory, such as the amount of new generation memory, the ratio between Eden and survivor, and so on. This parameter is suitable for manual optimization of memory when it is difficult to use, he can monitor the current state of the system, dynamic adjustment to achieve maximum throughput.

Here we only know about the next generation of collectors, the following picture to you to summarize:

But do not think that if you set this parameter (maxgcpausemills) set slightly smaller can be garbage back collection speed is faster, GC pause waiting time is to sacrifice the throughput

And the new generation of space to exchange: the system to lower the new generation, mobile phone 300MB is sure to be faster than the 500MB mobile phone, which is a direct result of garbage collection occurs more frequently,

Originally collected 10 seconds, each pause 100 milliseconds, now becomes 5 seconds to collect once, each pause 70 milliseconds. The pause time is indeed falling, but the throughput also drops.

After the-xx:useadaptivesizepolicy switch is turned on, you do not need to manually set the Cenozoic size, Eden and Survior area scale and promotion Laosheng object size (see Understanding Java Virtual Machine on page 79th)

JAVA Young Generation Collector Section Nineth

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.