当前位置:网站首页>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 .
边栏推荐
- TCP的三次握手和四次挥手
- Error: case label `15 'not within a switch statement
- 算数运算指令
- Restful style interface design
- 字节跳动海外技术团队再夺冠:高清视频编码已获17项第一
- Native JS realizes the functions of all selection and inverse selection -- Feng Hao's blog
- After the subscript is used to assign a value to the string type, the cout output variable is empty.
- ~72 horizontal and vertical alignment of text
- 字节跳动2022校招研发提前批宣讲会,同学们最关心的10个问题
- js垃圾回收机制和内存泄漏
猜你喜欢
~85 transition
README. txt
J'ai traversé le chemin le plus fou, le circuit cérébral d'un programmeur de saut d'octets
MP4格式详解
Which is more important for programming, practice or theory [there are some things recently, I don't have time to write an article, so I'll post an article on hydrology, and I'll fill in later]
Fdog series (4): use the QT framework to imitate QQ to realize the login interface, interface chapter.
When it comes to Google i/o, this is how ByteDance is applied to flutter
字节跳动技术面试官现身说法:我最想pick什么样的候选人
Solve the single thread scheduling problem of intel12 generation core CPU (II)
数据传送指令
随机推荐
DS18B20数字温度计系统设计
Saw local status change event StatusChangeEvent [timestamp=1644048792587, current=DOWN, previous=UP]
原型链继承
Train 100 pictures for 1 hour, and the style of the photos changes at will. There is a demo at the end of the article | siggraph 2021
Li Kou leetcode 280 weekly match
LeetCode 1545. Find the k-th bit in the nth binary string
js垃圾回收机制和内存泄漏
redux使用说明
JS encapsulates the method of array inversion -- Feng Hao's blog
Data config problem: the reference to entity 'useunicode' must end with ';' delimiter.
J'ai traversé le chemin le plus fou, le circuit cérébral d'un programmeur de saut d'octets
LeetCode 1552. Magnetic force between two balls
Fdog series (I): think about it. It's better to write a chat software. Then start with the imitation QQ registration page.
~70 row high
Mongodb在node中的使用
SQL快速入门
7-7 ring the stupid bell
Erlang installation
[unsolved]7-14 calculation diagram
CMake速成