Sorting out some problems encountered during the interview

1. The difference between HashMap and HashTable , when to use HashMap and when to use HashTable

Use HashMap when you don’t have to consider thread safety issues. ConcurrentHashMap is recommended for multi-threaded situations.

 

2. How many types of dependency injection are there?

1. Interface injection

2.set method injection

3. Constructor injection

3. What are the characteristics of things?

1. Atomicity

2. Consistency

3. Isolation

4. Endurance

 

4. Is the controller of action and spring mvc singleton or multiple instances respectively, what is the difference?

There are many cases of action, one request corresponds to one action, and there is no thread safety issue;

The controller is singleton by default, and there are thread safety issues when multi-threaded calls, so independent member variables should be avoided. If you need member variables, you can use ThreadLocal

Five, dubbo's provider thread pool

There are two types, 1. IO processing thread pool. (Configure directly through netty, etc.). 2. Service call thread pool.

The service call thread pool can be set to the following three configurations:

fixed Thread pool of fixed size. Threads are created at startup, not closed, and held all the time. 
cached Cache thread pool, automatically deleted after one minute of idle, and rebuilt when needed. 
limited scalable thread pool, but the number of threads in the pool will only grow and not shrink. (In order to avoid performance problems caused by sudden large flow during contraction).

Six, hashmap, hashset related issues

HashMap initial size 16

Use hash table (hash table) for data storage, and use chain address method to resolve conflicts

1. Features of hashmap1.8

When the length of the linked list is greater than or equal to 8, convert the linked list to a red-black tree for storage

2. Growth factor of hashmap

Each time the expansion is performed to the power of two, the expansion is twice the original capacity

3. Can an object be stored in hashset twice (the physical address is the same)

According to the hashmap source code, it is mainly related to the hashcode. As long as the hashcode of the object is not equal twice, it is possible to store an object in the hashset twice.

4. It can be achieved by using arrays and linked lists before, why does jdk1.8 use red-black trees?

From the source code, we know that the author of the HashMap source code calculated by Poisson distribution. When the number of nodes in the bucket is 8, the probability of occurrence is 6 per billion. Therefore, the common situation is that the number of nodes in the bucket is less than 8. The query performance of the time-linked list is similar to that of the red-black tree, because it takes time and space to transform into a tree, so there is no need to transform into a tree at this time.

Since the probability of occurrence is so low when the number is 8, why do we need to tree when the number of linked lists is greater than 8 to optimize this almost never-occurring scene?

First of all, we need to know under what circumstances the almost impossible probability of 6 per billion is established. The answer is: based on a good hash algorithm, such as the hash algorithm of the packaging class such as String, Integer, and if it happens once the element in the bucket occurs If it is greater than 8, it means that it is an abnormal situation. A hash algorithm with greater conflict may be used. At this time, the probability of the number of buckets exceeding 8 is very high. There may be n keys conflicting in the same bucket. Looking at the average query complexity of the linked list and the time complexity of the red-black tree, you will know why the red-black tree is introduced.

For example, if the hash algorithm is not well written, 1024 keys conflict in a bucket, and an average of 512 queries is required to use the linked list, but the red-black tree is only 10 times. The introduction of the red-black tree ensures that there are a large number of hash conflicts. , HashMap also has good query performance
5, what is Hash conflict

The hashCode of two different objects is the same, this phenomenon is called hash conflict

7. Where is aop used in the project?

Log, url access permission interception, paging, data source injection result set processing and resource closure, unified exception handling, caching, SMS anti-brushing, etc.

 

Eight, multi-threaded related interview questions

1. What is the difference between start and run

The start method tells the cpu thread to be ready, you can call the Run method, and calling the Run method directly will not start a new thread

2. What are the methods for threads

sleep,yield,join,daemon,setPriority

Object comes with thread related methods wait, notify, notifyAll

3. The difference between sleep and wait

Sleep releases cpu control and does not release the lock;

wait releases cpu control and releases the lock

4. Thread state transition

Guess you like

Origin blog.csdn.net/noob9527/article/details/72869080