Give it a like and take a look. Good habit! In this paper, making github.com/OUYANGSIHAI… It has been included. This is the summary of Java interview for first-tier big factories that I spent 3 months summarizing. I have received offers from Tencent and other big factories.
Here tell you interview one of the most common garbage collector, I told you guys, you don’t have to suspect that CMS garbage collector must be the most common problems, just ask the Java virtual machine, the interviewer would ask your CMS, and of course the G1 is the garbage collector, so, the details about the garbage collector, Be sure to master it well, as long as you master it in place, you will be satisfied with the interviewer.
But, say a dross word, luck is bad, the interviewer is not right, there is no way of things, can only recognize the plant, feel good, just feel yourself, in the heart of the interviewer, you are scum!!
Ok, let’s begin the interview process. This article tries to take a different approach by listing some common interview questions and then answering them.
The body of the
This spring, due to the epidemic, all interviews will be conducted online and remotely, so if you are lucky, you can see the interviewer’s face, if you are unlucky, you can only be seen by the interviewer’s nervous appearance, but you can only see a black screen, haha!
This is the real scene!
However, there is no interviewer figure, only beat again and again!!
Tell me about CMS garbage collector, young man!
This topic, scared out of a cold sweat, almost did not review this CMS, fortunately last night to read it.
So I… The operation was as fierce as a tiger.
CMS (Concurrent Mark Sweep) collector is a collector aimed at obtaining the shortest recovery pause time. It is implemented based on the “mark-sweep” algorithm, and is commonly used in Java applications on the server of Internet sites or B/S systems.
The result is a nervous remember so much, the interviewer certainly not satisfied, at this time, the interviewer’s routine operation is, continue to torture, he thought, you may forget, I remind remind you!
Can you tell me the whole process of working with the CMS collector?
At this time, the interviewer will comfort you that you do not have to be nervous, but comfort is comfort, finally hang up is another matter.
So I started answering questions again.
The CMS process has seven steps:
- Initial tag, which causes STW;
- Concurrent flags, running at the same time as user threads;
- Pre-clean, run at the same time as the user thread;
- Terminable pre-cleaning, running at the same time as the user thread;
- Re-marking, which results in SWT;
- Concurrent cleanup, running at the same time as the user thread;
Actually, you should probably answer four. These are the ones.
- Initial tagging: Simply tagging objects that GC Roots can be directly associated with is fast and requires “Stop The World”.
- Concurrent marking: The process of GC Roots Tracing, which takes the longest.
- Relabelling: In order to correct the marking record of the part of the object that was marked during the concurrent marking as the user program continued to operate, the pause time in this phase is generally slightly longer than the initial marking phase, but much shorter than the concurrent marking phase. This stage also needs to “Stop The World”.
- Concurrent cleanup.
You think this is all right, the interviewer will say yes, if you can, then I guess you are cold!
Interviewer: Are there any downsides to CMS?
I… Well, I’m not the one to blame, am I?
In fact, CMS has been a reliable GC collector over the years, but there are some shortcomings.
First, the problem of garbage fragments. As we all know, CMS uses mark-clear algorithm, so it is inevitable that garbage fragments will appear. Secondly, generally, 80% of THE GC time of CMS is in remark stage, which has a long pause time. Among the four major stages of CMS, the most time-consuming one is the re-marking stage. Concurrent mode failure. Concurrent mode failure. Concurrent mode failure.
This exception occurs while the CMS is collecting. Implementation of the CMS GC, business threads are running at the same time, when the young with space is full, when performing ygc needs will survive object into old age, and at that time, the old s space is insufficient, the CMS haven’t had a chance to recycle old belt, or when doing the Minor GC, new generation rescue space not put, need to put into old age, And the old age also can not put and produced.
Fourth, promotion failed, this problem refers to the problem that during the Minor GC, the Survivor space is insufficient, and the object can only be placed in the old decade, and the old decade can not be placed in the old decade. Most of the problems are caused by the old decade has enough free space, but because there are many fragments. The object that the new generation will move to the old age zone is relatively large, and there is no continuous area to store this object.
The interviewer sees that you have mastered so well, the heart has given you a thumbs up, but, the interviewer thinks you are excellent, also want to see how much you have in the end.
Since you know there are so many disadvantages, do you know how to solve them?
This really was asked meng, do you think I what metropolis !!!!
But I still have to tell you, or the next time I’m asked, I might be the one to blame.
-
Debris problem: in view of this problem, this time we need to use this parameter: – XX: CMSFullGCsBeforeCompaction = n mean in the last time the CMS concurrent GC after the execution, exactly how many times have to perform full GC will do compression. The default is 0, which means that in the default configuration, compression is done every time the CMS GC fails and goes to full GC.
-
concurrent mode failure
The solution to this problem is as simple as setting two parameters
+ UseCMSInitiatingOccupancyOnly – – XX: XX: CMSInitiatingOccupancyFraction = 60: refers to a set of CMS in began to GC in memory usage rate of 60%.
Why are these two parameters set? Because the user thread needs to run during the garbage collection phase, there is still enough memory left for the user thread to use, so the CMS collector cannot wait until the old age is almost completely filled up before collecting, as other collectors do.
Of course, do not set too high, such as 90%, this time although less GC times, but will result in a small user thread space, inefficient, too low 10%, you think about how it will be, experience!
Ha ha, everything is ok, this point said, it is estimated that the interviewer has fallen in love with me, quickly recruit me to work…
- Remark Phase has a long pause time: The solution to this problem is simple. Join in
-XX:+CMSScavengeBeforeRemark
. Do this before performing remarkYoung GC
, the purpose is to reduce the invalid reference of the young generation to the old generation and reduce the cost of remark.
At the end
At this point, the interviewer said to you: the young man is excellent and thinks deeply. When can he come to our company for internship? Our company has a high chance of becoming a full-time employee.
In addition, I spent 3 months compiling the summary of Java learning and interviewing into an ebook! Directory as follows
Now free to share everyone, in my public number to learn Java reply Java interview can be obtained.
Have a harvest? Hope the old iron people come to a triple whammy, give more people to see this article
1, old friends, follow my original wechat public account “Learn Java well”, focusing on Java, data structure and algorithm, micro services, middleware and other technology sharing, to ensure that you will gain something after reading.
Give me a thumbs up, can let more people see this article, by the way inspire me to continue to write, hee hee.
“Like” is the biggest encouragement for me