Java generational thinking and Java generational thinking
We all know that java gc is based on java's generational premise. Both CMS and G1 are based on the generational thought: the old age and the new generation
Thought 1: Why can we perform generational division?
1. The object lifecycle in java is different. The age concept in gc is involved.
Short-lived objects, such as temporary variables of methods.
Long-lived objects, such as cache objects and connection pools.
2. The reference relationship between a long-lived object and a short-lived object is relatively small (important ).
Thinking 2: What are the advantages of generational division?
From the perspective of garbage collection, different collection algorithms can be used for different generations to improve the efficiency of garbage collection and reduce the stw time of the system.
Think 3: Do generations have no disadvantages?
Suppose we have a java System in a scenario, which is not in line with the premise of thinking about the java generational division, the generational garbage collection algorithm will affect the system performance. (We look forward to encountering such a system ....)
Thinking 4: Just for garbage collection?
As mentioned in the first point, the service is divided into java objects, and java objects are divided into two processes: Allocation and collection. Therefore, we need to combine object allocation and garbage collection to consider generation division, the goal of generation is to increase the efficiency of object allocation and garbage collection.