当前位置:网站首页>Eight part essay that everyone likes
Eight part essay that everyone likes
2022-07-06 16:56:00 【LuckyShawn】
One 、 Basics
1. Basic data type
- integer :byte(8)、short(16)、int(32)、long(64)
- floating-point :float(32)、double(64)
- Boolean type :boolean(8)
- Character :char(16)
2.String、StringBuffer、StringBuilder
- String from char[] Array composition , Used final modification , Is immutable , It can be understood as a constant , Thread safety ; Yes String Each time a change is made, a new String object , Then point the pointer to the new reference object .
- StringBuffer Thread safety ;StringBuiler Thread unsafe .
- To manipulate a small amount of character data String; Single thread operation of a large amount of data with StringBuilder; Multithreading a lot of data with StringBuffer.
Two 、 aggregate
1.List( Linear structure )
- ArrayList Object[] Array implementation , The default size is 10 , Support random access , Continuous memory space , Insert end time complexity o(1), Insert first i Location time complexity o(n - i). Capacity expansion , The size changes to 1.5 times ,Arrays.copyOf( Bottom System.ArrayCopy), Copy to new array , Pointer to the new array .
- Vector similar ArrayList, Thread safety , The default growth of capacity expansion is the original 2 times , You can also specify the length of the growth space .
- LinkedList Based on linked list ,1.7 Double linked list ,1.6 It is a two-way circular linked list , Canceling the loop can better distinguish the head from the tail .
2.Map(key-value Key value pair )
HashMap
- Underlying data structure ,JDK 1.8 It's an array + Linked list + Red and black trees ,JDK 1.7 No red and black trees . The list length is greater than 8 when , Turn it into a red-black tree , Optimize query efficiency .
- The initial capacity is 16, adopt tableSizeFor The guaranteed capacity is 2 Power square . Addressing mode , High XOR ,(n-1)&h modulus , Optimize speed .
- Expansion mechanism , When the number of elements is greater than the capacity x Load factor 0.75 when , Capacity expanded to the original 2 times , Create a new array , Then move to the new array .
- be based on Map Realization . Thread unsafe .
HashMap (1.7) Multithreaded circular linked list problem
- In multithreaded environment , When expanding the capacity ,1.7 Under the HashMap Will form a circular linked list .
- How to form a circular linked list : Suppose there is a HashMap Capacity of 2 , Subscript in the array 1 Position in A -> B Linked list storage . There is a thread on the map do put operation , Due to triggering expansion conditions , Need to expand . At this time, another thread also put operation , Capacity expansion is also required , And completed the expansion operation , Since copying to the new array is a header insert , therefore 1 The position changes to B -> A . At this time, the first thread continues to expand , Copy first A , And then copy it B , To determine B.next Whether it is empty time , Because the second thread does the capacity expansion operation , Lead to B.next = A, So in the A Put it in B front ,A.next It's equal to B , Cause the circular linked list to appear .
HashTable
- Thread safety , The method basically uses Synchronized modification .
- The initial capacity is 11 , Capacity for 2n + 1 .
- Inherit Dictionary class .
3、 ... and 、 Multithreading
volatile
- In multithreaded environment , Ensure the visibility of variables . Used volatile After modifying variables , After the variable is modified, it will be synchronized to main memory immediately , Every time this variable is used, it will be refreshed from main memory .
- prohibit JVM Instruction reordering .
- Why the singleton mode double check lock variable is used volatile modification ? prohibit JVM Instruction reordering ,new Object() There are three steps : Apply for memory space , Assign a memory space reference to a variable , Variable initialization . If reordering is not prohibited , It is possible to get an uninitialized variable .
Four 、JAVA virtual machine
1. Memory model
- Pile up Shared by threads , Deposit new Out object , This is the main working area of the garbage collector .
- Stack Thread private , It is divided into Java Virtual machine stack and local method stack , Store the local variable table 、 Stack operation 、 Dynamic links 、 Method exit information , The execution of the method corresponds to the process from entering the stack to exiting the stack .
- Method area Thread sharing , Store the loaded class information 、 Constant 、 Static variables 、 Real time compiler compiled code and other information ,JDK 1.8 The method area is replaced by a meta space , Use direct memory .
2. Class loading mechanism
- Parent delegation mode
When a class needs to be loaded , Judge whether the current class has been loaded . Classes that have already been loaded will directly return , Otherwise, it will try to load . When loading , First, the request will be delegated to the parent loader loadClass() Handle , So all requests should eventually be sent to the top-level boot loader BootstrapClassLoader in . When the parent loader cannot process , It's up to me to deal with . When the parent loader is null when , Will use boot class loader BootstrapClassLoader As a parent loader .
3. It can be used as GCRoot The object of
- a) Objects referenced in the virtual machine stack ( Local variables in stack frames )
- b) Object referenced by a class static property in a method area
- c) The object referenced by a constant in the method area
- d) Local method stack Native Method reference object
5、 ... and 、 database
1. Clustered index and non clustered index
- All use B+ Trees as data structures
- The data in the cluster index exists in the leaf node of the primary key index , obtain key Or get data ; There is a separate space for non clustered index data .
- The leaf node of the auxiliary index in the cluster index stores the primary key ; In the non clustered index, the leaf node stores the address of the data ;
- The advantage of clustered index is to find data when you find the primary key , Just one disk IO ; When B+ When the nodes of the tree change , The address will also change , At this time, the non clustered index needs to update all addresses , Increased overhead .
2. Why use B+ Tree as index
disk IO The number of times is an important index to measure the quality of index data structure
B+ Tree as database index :
1. A single node stores more elements , Make the tree fatter , Of the query IO Fewer times
2. All data is placed on leaf nodes , All queries need to find leaf nodes , Query performance is stable
3. Because leaf nodes form an ordered linked list , Easy range query .
3. When can I use it B Tree index
- The primary foreign key needs to be indexed
- It is best to index the data columns that are often queried
- For data columns that need to be queried quickly or frequently within the specified range , Because the index is sorted , Its specified range is continuous , Queries can take advantage of the sorting of indexes , Faster query time
- Often used in where Data column in clause , Index on where Clause , For data columns that need to be accelerated or retrieved frequently , These data columns that often participate in the query can be queried according to the sort of index , Faster query time .
边栏推荐
猜你喜欢
LeetCode 1557. The minimum number of points that can reach all points
CMake速成
Mp4 format details
Cmake Express
「博士毕业一年,我拿下 ACL Best Paper」
Data config problem: the reference to entity 'useunicode' must end with ';' delimiter.
Solr new core
100张图训练1小时,照片风格随意变,文末有Demo试玩|SIGGRAPH 2021
Shell_ 05_ operator
LeetCode 1552. Magnetic force between two balls
随机推荐
原型链继承
ByteDance open source Gan model compression framework, saving up to 97.8% of computing power - iccv 2021
One hundred questions of image processing (1-10)
音视频开发面试题
After the subscript is used to assign a value to the string type, the cout output variable is empty.
100张图训练1小时,照片风格随意变,文末有Demo试玩|SIGGRAPH 2021
Yao BanZhi and his team came together, and the competition experts gathered together. What fairy programming competition is this?
Ffmpeg command line use
Detailed explanation of FLV format
字节跳动春招攻略:学长学姐笔经面经,还有出题人「锦囊」
LeetCode 1584. Minimum cost of connecting all points
Solr standalone installation
~73 other text styles
Saw local status change event StatusChangeEvent [timestamp=1644048792587, current=DOWN, previous=UP]
Shell_ 05_ operator
[unsolved] 7-15 shout mountain
Soft music -js find the number of times that character appears in the string - Feng Hao's blog
~70 row high
字节跳动2022校招研发提前批宣讲会,同学们最关心的10个问题
Some instructions on whether to call destructor when QT window closes and application stops