Go: Interview question: "Can you talk about when the Java GC was, what to do and what to do?" ”

Source: Internet
Author: User

Transferred from: http://jeromecen1021.blog.163.com/blog/static/18851527120117274624888/

Interview Topics:

The people of the Earth know that Java has a thing called the garbage collector, it makes the object created does not need to be like c/cpp, delete, free, can you talk about when the GC is, to what, what things?

A. Answer: When?

      • 1. When the system is idle.
      • Analysis: This answer accounts for about 30%, in general I will be ready to turn to other topics, such as algorithms, such as SSH to see if you can explore other aspects of his good.

      • 2. The system itself decides, unpredictable time/call System.GC ().
      • Analysis: This answer accounted for about 55%, most of the fresh students can answer this answer, at least not a mistake is it, the follow-up should be broken down in the end is the language of the expression lead to the answer is too general, or itself only such a vague understanding.

      • 3. Can say the new generation, the old generation structure, can propose minor gc/full GC
      • Analysis: To this level, basically can say that the GC operation has a conceptual understanding, such as read "Deep JVM virtual Machine" and the like.  This part is less than 10%.

      • 4. Can explain the trigger condition of minor gc/full GC, the trigger condition of oom, and reduce the strategy of GC tuning.
      • Analysis: List some of my expected answers: Eden is full of minor GC, the object of ascending to the old age is greater than the old age of the rest of the space full GC, or less than when the Handlepromotionfailure parameter forced full GC , GC and non-GC time consuming more than gctimeratio limit caused by oom, tuning such as through Newratio control of the new generation of the old age ratio, through maxtenuringthreshold control into old age before the number of survival, etc... Can answer that this stage will bring me higher expectations, of course, the interview when normal people will not remember the spelling of each parameter, I wrote this paragraph when I also turned over the manual.  The answer to this section is less than 2%.

        Summary: Programmers can not control the time, the system in the unpredictable time call System.GC () function, of course, through tuning, with Newratio control the ratio of newobject and Oldobject,  Using Maxtenuringthreshold to control the number of times to enter the Oldobject causes the Oldobject storage space to delay to full GC, which causes the timer to delay the time delay of Oom for the GC time to prolong the object lifetime.




two. Answer: What's the thing?

      • 1. Objects that are not used.
      • Analysis: The equivalent of no answer, the question is to ask what the object is "not used objects." accounted for about 30%.
      • 2. An object that is out of scope object/reference count is empty.
      • Analysis: The 2 answers stood at 60%, a fairly high percentage, and the teacher was taught to teach Java at school. The first answer does not solve my question, how exactly does the GC determine which objects are not in scope?  As for the reference count to determine whether the object can be collected, I can add one of the following example to let the interviewer analyze Obj1, OBJ2 will be GC off?

        class c{

    public
        Object x;

            } 

        C obj1, obj2 = new C ();

        obj1.x = obj2;

        obj2.x = obj1;

        obj1, obj2 = null;

      • 3. Search from GC root to search for objects not found.
      • Analysis: Root object lookup, tag is pretty good, less than 5% people can answer this step, is estimated to be a reference counting way too "deep in the hearts of the public."  Basically you can get all the points for this problem.

        PS: There are candidates in this question to add strong references, weak references, soft references, phantom reference differences, not the answer I want to ask, but you can add points.

      • 4. cannot be searched from root, and after the first mark, cleanup, there is still no Resurrection object.
      • Analysis: I look forward to the answer.  But it's true that very few interviewers will answer that, so in my mind I answer the 3rd I give all the points.

        Summary: Objects that are out of scope or reference count are empty, search for objects that cannot be found from GC root, and are marked, cleaned, and still have no resurrected objects.




three. Answer: What do you do?

      • 1. Remove unused objects and free up memory space.
      • Analysis: With question 2 1th. 40%.
      • 2. Add some instructions such as stopping other threads from executing, running finalize, and so on.
      • Analysis: At least the problem materialized some, if like answer 1, I can hardly find the topic in the answer to continue to expand, about 40% of the people.

        add a little digression, the interview I most afraid of the answer is "This problem I can not say, but encountered when I surf the internet to make it." Do program development really is not to exercise anise beans "anise" There are several ways, do not memorize I agree, I will not correct grammar, words, but how much you say a thought ah, to directly answer an Internet search, I have no way to get the information can be evaluated candidates, it is difficult to continue to explore the topic from the answer to discuss.  It is recommended that you try to answer the areas you are familiar with and discuss, and show them to the interviewer's best side.

      • 3. Can say what the new generation is doing is replication cleanup, from Survivor, to Survivor is what to do, the old age is to mark clean up, Mark clean up after the fragment to do not tidy, copy cleanup and tag cleanup have what advantages and disadvantages.
      • Analysis: Also read the "Deep JVM virtual machine" Basic can answer this degree, in fact, to this extent I have been more than expected.  Also less than 10%.

      • 4. In addition to 3, can also be clear serial, parallel (collation/Not defragment), CMS, such as the role of the collector can be the age, characteristics, advantages and disadvantages, and can explain the control/adjustment of the collector selection method.
      • Analysis: The 4th with the above 2 questions.




Summary: Delete unused objects, reclaim memory space, run the default finalize, and of course the programmer wants to invoke the dipose call to free resources such as file handle, the JVM uses from survivor, to survivor flag it clean, The object can also be resurrected after it is serialized.

Do not say that Google under the Internet, even say that they have previously encountered such a problem is how to deal with the knowledge of the idea, and then can ask the examiner, so that the technical type of the examiner for how to continue the topic and you have no words, hehe.

Go: Interview question: "Can you talk about when the Java GC was, what to do and what to do?" The

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.