Java knowledge point summary (irregular updates) and java regular updates

Source: Internet
Author: User

Java knowledge point summary (irregular updates) and java regular updates
1. Generation-based garbage collection Algorithm

Design Concept: groups objects based on the length of life into young and old generations. Newly created objects are divided into young generations. If the objects still survive after several recycles, then we divide this object into the old generation. The collection frequency of the old generation is not as frequent as that of the young generation, which reduces the number of objects to be scanned during each garbage collection, thus improving the efficiency of garbage collection.

Divide the heap into several sub-heaps, each of which corresponds to an age generation:

JVM divides the entire heap into the Young, Old, and Perm areas to store objects of different ages. The objects in these three areas are different as follows:

Young: it is also divided into Eden and two vor regions. All newly created objects are in Eden, when the Eden area is full, minor GC is triggered to copy the objects that are still alive in the Eden area to one of the two vor areas. The surviving objects in the other vor area are also copied to the same vor area, to ensure that there is always an empty vor zone.

Old: stores the minor GC objects triggered after the startup vor of the Young area is full. When the Eden area is full, the objects are stored in the same vor area, if the primary vor area still does not store these objects, the GC collector will store these objects directly to the Old area. If the objects in the primary vor area are Old enough, they will be directly stored in the Old area, if the Old zone is Full, Full GC is triggered to reclaim the entire heap memory.

Perm zone: stores Class objects. garbage collection in the Perm zone is also triggered by Full GC.

2. JVM parameter configuration

  

Reference: http://www.cnblogs.com/likehua/p/3369823.html,http://www.cnblogs.com/redcreen/archive/2011/05/04/2037057.html

  

The Minimum Memory value is-Xms, that is, 10240 m.

-Xmn 5120 m: the size of the young generation.-xxw.vorratio = 3, that is, Eden: FromSurvivor: tow.vor =; therefore, the total value of swap VOR is 10240 * (2/5) = 2048 m.

3. thread security of the Collection framework

  

A, Vector is equivalent to A thread-safe ListB. HashMap is non-thread-safe. Its corresponding thread security class is HashTableC, Arraylist is non-thread-safe, and its corresponding thread security class is VectorD, stringBuffer is thread-safe, which is equivalent to a thread-safe StringBuilderE. Properties implements the Map interface, which is thread-safe. 4. The Collection interface and the Map interface are shown in the following two figures:

  

5. HashMap sorting
Public class SortMap {public static void main (String [] args) {Map <String, Integer> map = new HashMap <String, Integer> (); map. put ("1d", 4); map. put ("2b", 3); map. put ("3a", 1); map. put ("4c", 2); System. out. println ("Raw data:"); // for (String s: map. keySet () {System. out. println (s + ":" + map. get (s) ;}list <Map. entry <String, Integer> list = new ArrayList <Map. entry <String, Integer> (map. entrySet (); // sort Collections by key value. sort (list, new Comparator <Map. entry <String, Integer> () {@ Override public int compare (Map. entry <String, Integer> o1, Map. entry <String, Integer> o2) {return o1.getKey (). toString (). compareTo (o2.toString () ;}}); System. out. println ("sort by key value:"); // for (Entry <String, Integer> entry: list) {System. out. println (entry. getKey () + ":" + entry. getValue ();} // sort Collections by value. sort (list, new Comparator <Map. entry <String, Integer> () {@ Override public int compare (Map. entry <String, Integer> o1, Map. entry <String, Integer> o2) {return o1.getValue ()-o2.getValue () ;}}); System. out. println ("sort by value:"); // for (Entry <String, Integer> entry: list) {System. out. println (entry. getKey () + ":" + entry. getValue ());}}}

 

 

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.