Chengdu face questions at least twenty 16k

Interview questions:
HashMap principle underlying implementation, red-black trees, B + tree, B-tree structure principle, volatile keyword, CAS (compare and swap) implement the principle of
what Spring AOP and the IOC that? What are the usage scenarios? Spring transaction, the transaction attributes, communication behavior, isolation level
Spring and SpringMVC, MyBatis and SpringBoot comments are what? Works SpringMVC advantage of, SpringBoot framework, advantages MyBatis framework
SpringCould components which, what is their role? (Say seventy-eight) What is micro-services CAP?
Design pattern (say five or six)
Redis supported data types and usage scenarios, persistence, Sentinel mechanism, breakdown cache, the cache penetrate
what thread is that there are several ways to achieve, what is the difference between them is that the thread pool the principle, JUC and contracting, ThreadLocal with Lock and Synchronize difference, voliate key role in
how to ensure data consistency (a system writes data between distributed transaction (different system, B system for some reason is not written successfully , resulting in inconsistent data))
security issues (data tampering (to get the URL of others, tampering with the data (amount) sent to the system))
limits the use of the index, sql optimization which, data synchronization (caching, database data synchronization)
Bean there are several steps to initialize the object, its life cycle
JVM memory models, algorithms, garbage collector, tuning, class loading mechanism (delegated parents)
how to design a spike system, (high concurrent high-availability distributed cluster)
pessimistic locking, optimistic locking, read-write locks, row locks, table locks, spin locks, deadlocks, distributed lock, thread synchronization lock, What fair locks, locks are unfair
Heap overflow, stack overflow occurs scenes and solutions
tell the difference between several MQ, and why this MQ, the message sent repeatedly (idempotency), failed to send a message, the message substitution, for a long time not receive the message , caused by too much to receive messages sent unsuccessfully
single sign-on implementation principle
if there are hundreds of millions of pieces of data, you how to quickly find the data (several simple algorithms) one in which you want
to run the principle of Dubbo, support any agreement, and SpringCould compared why efficiency is higher, Zookeeper underlying principle
if you take a team allows you to design a system, you need to consider what
Description: here's the answer I'm back up slowly, you first looked at, if they feel their technical capacity below you can review a strong message, as concise language knowledge will expand more, I will use the right

answer:

HashMap principle underlying implementation, red-black trees, B + tree, B-tree structure principle, volatile keyword, CAS (Compare and switching) to achieve the principle of
first class HashMap is an implementation of the Map, and the Map is stored in the form of key-value pair (key, value )of. It can be seen as a one Entry. Entry to the position stored by the key to decide.

Map the key is disordered and unrepeatable, all the key set can be viewed as a set, if there is the Map key if custom objects class must override equals and hashCode method, because if not rewriting, using the Object class equals and hashCode method of comparison is not more than the content of the memory address value.

The Map value is disordered repeatable, all value can be seen as a collection of Collection, the Map value if custom objects class must override equals method.

As to override the hashCode and equals what were doing, take hashMap underlying principle is:

When we store an element (k1, v1) to HashMap, first decide hashCode stored in an array according to the method of k1 position.

If this is not the position of the other elements, the (k1, v1) Node type directly into the array, the array 16 is the initial capacity, the default load factor is 0.75, i.e. when the element 12 when applied to the underlying expansion will be , expansion is 2 times the original. If the location has other elements (K2, v2), and then calls k2 k1 equals method compares two elements are the same, if the result is true, the two elements are the same as described, with alternative v2 v1, if the return false, the two elements are not the same, it will be (k1, v1) is stored in the form of a linked list.

But when more data in a linked list, the query efficiency will decline, so do the JDK1.8 version of an upgrade, that is, when the list of elements to 8, the list will be replaced by red-black tree to improve search efficiency . Because for search, insert, delete under many operating conditions, the efficiency of the use of red-black tree is higher.

The reason is because the red-black tree is a special binary search tree, a binary search tree all the nodes in the left subtree are less than the node, all nodes in the right subtree are greater than the node, it can be done by comparing the size of the relationship fast retrieval.

After a red-black tree insert or delete a node, a red-black tree is changed, five properties may not meet the red-black tree, no longer is a red-black tree, but rather an ordinary tree , by left and right hand, the Fengyun tree again become a red-black tree. 5 Properties of red-black tree (black root node, each node is a black or red, each leaf node is a black, red if a node is its child nodes must be black, from one node to the node All paths descendants external node comprising the same number of black dots)



and the binary tree structure like this scenario is more common to use two kinds of index Mysql engine, Myisam using a B-tree, InnoDB using a B + tree.

First, its B-tree each node is Key.value tuple, its sort key is increasing from left to right, value storing data. Such a high performance mode in terms of reading the data, because a separate index file, the storage file has three Myisam .frm file table structure, .MYD data file, the index file is .MYI. But Myisam also some disadvantages it only supports table-level locking, does not support row-level locking does not support transactions, foreign keys, etc., it is generally used for large data storage.



Then InnoDB, it's a small store files compared Myisam index file, which is based ID for the index data storage, data have now been in existence for leaf nodes, the non-leaf node index. These nodes scattered on the index page. In InnoDB, each page default 16KB, assuming that the index is a long type of data 8B, there 4B, there are other data pages 6B after each number key, then the fan-out factor for each page of 16KB / (8B + 4B + 6B) ≈1000, where each page can be indexed 1000 key. When the height h = 3, s = 1000 ^ 3 = 10 Yi! ! In other words, InnoDB by three index page I / O, you can index 1 billion key, rather than the line store index leaf node, the number of the more, the number of I / O is less. And Myisam at each node for storing data and indexes, thus reducing the number of indexes per store. And it supports InnoDB row-level, table-level locking, and also supports transactions, foreign keys.



In addition to the actual process of using HashMap or there will be some thread safety issues:

HashMap is not thread-safe in a multithreaded environment, use Hashmap be put action will cause an infinite loop, resulting in close to 100% CPU utilization, and will throw an exception concurrent modification, the cause is concurrent threads for resources, resulting in the modification data, he is writing a thread, a thread over the competition, leading to write thread the process is interrupted by another thread, leading to inconsistent data.

HashTable are thread-safe, but the realization costs are too great, simple and crude, get / put all operations are synchronized, which is equivalent to the entire hash table plus a big lock. Multi-threaded access, as long as there is one thread to access or manipulate the object, that other threads can only be blocked, the equivalent of all the operations serialized in the competitive scenario of concurrent performance will be very poor.

In response hashmap insecurity can be used in a concurrent environment, ConcurrentHashMap a lot of use of volatile, CAS and other techniques to reduce the impact of lock contention for performance.

In JDK1.7 version ConcurrentHashMap avoid global lock, the local lock into (locking segment), the segment lock technology, the data storage segments by, and to each piece of data with a lock, when a thread holding the lock access one segment data, the other segment of data can also be accessed by other threads, to achieve true concurrent access. But a side effect of this structure is Hash process than ordinary HashMap longer.

Therefore JDK1.8 version value used in the internal volatile CurrentHashMap modification to ensure visibility and prohibits concurrent instruction rearrangement, but does not guarantee atomicity volatile, used to ensure atomicity using CAS (Compare exchange) optimism lock to resolve.

CAS operation includes three operands - a memory location (V), is expected to original value (A) and the new value (B).

If the value of the memory address and the value of A which is the same, then the values will be updated to the memory inside B. CAS is to get the data through an infinite loop, Ruoguo cycle in the first round, a thread gets inside the address value is modified b-threaded, then a thread needs to spin cycle to the next possible opportunity to perform.

There are three volatile properties: Visibility, does not guarantee atomicity, disable command rearrangement.

Visibility: Thread 1 to take data from the main memory 1 to its own thread work space operations (assumed to be plus 1) at this time has been changed to the data 1 data 2, and will notify the other thread write back to main memory data 2 (thread 2, thread 3), the data in the main memory data 1 has been changed to 2, and let other threads to re-take the new data (data 2).

Does not guarantee atomicity: Thread 1 took a data value from the main memory 1 to which their work space as increment operation, the value becomes 2, write-back to main memory, and yet had time to inform other threads, thread 1 was preempted thread 2, the CPU allocation, is suspended thread 1, thread 2 or main memory holding data of the original value of 1 plus 1, the value becomes 2, write-back to main memory, the main memory is Alternatively into 2 2, then the notification to the thread 1, thread 2 get the value back to main memory 2 data.

Prohibit instruction reordering: First instruction reordering is not always program execution from the execution of down, like the college entrance examination answer, you can easily do first difficult topic to do, then do question the order is not from the the down. Prohibit instruction reordering put an end to this situation.

(General interviewer asks you can ask from java basis, most will ask a question to the collection of this piece, and a collection of more ask a HashMap, this time you can ever take these directions interviewer asks you, and extended depth enough, so the above dry enough for you to say it ten minutes, after winning the first question, the interviewer your mind at least simple enough solid foundation, the first brownie points on the left)

the Spring of What AOP and IOC that? What are the usage scenarios? Spring transaction and database services, communication behavior, database isolation level
AOP: Aspect Oriented Programming.

That is to add additional features in a functional module, for example, say you want to take down a courier, you say to your colleagues help me also take the chant, you will take the opportunity to take up. Do not use AOP if some packages and classes in the system at work, such as logging, transaction and exception handling, then you have to implement them in each of the classes and methods. Each class code tangling and methods are included in the log, and the exception handling transaction even business logic. In one such method, it is difficult to distinguish between code that actually do what processing. AOP does is all scattered throughout the transaction code into one section of the transaction.

For example, I now want to get a log, recording method some time interfaces call. Use Aop I can insert a piece of code before this interface to record the start time, behind this interface to insert a piece of code recording end time.

Or you go to access the database, and you do not want Affairs (too much trouble), so, Spring before you access the database, automatically help you open the transaction, after the end of your access to the database, automatically help you commit / rollback transaction!

You can turn on exception handling around advice, once running the interface error, jump around advice catch the exception exception-handling page.

Spring AOP using dynamic proxy, a so-called dynamic proxy AOP framework that is not to modify the byte code, but rather generates a temporary method AOP object in memory, the object contains all AOP a target object, and in particular the cut-off point to do enhancement processing, and the callback original object. It's dynamic proxy There are two main ways, JDK dynamic proxies and CGLIB dynamic proxy. JDK dynamic proxy proxy class to receive by reflection, and requires the proxy class must implement an interface. The core JDK dynamic proxy is InvocationHandler interface and the Proxy class. If the target class does not implement the interface, then Spring AOP will choose to use dynamic proxy CGLIB target class. CGLIB is a code generation library can be dynamically generated subclass of a class, note that at runtime, CGLIB by inheritance way to do dynamic proxy, so if a class is marked as final, then it is not CGLIB do use dynamic proxies.

IOC: dependency injection or called inversion of control.

All need new Object Under normal circumstances we use an object () is. The ioc is to advance the object you want to use to create a good spring into the container inside.

All need to use the class will be registered in the spring container, tell spring you are something, you need something, then spring will be the appropriate time, the things you want to take the initiative to give you the system is running, but also to put you over other things you need. All of the class is created, destroyed by the spring to control, that control object is no longer referenced its object life cycle, but the spring. DI (DI) is actually another way of saying the IOC, in fact, they are the same at different angles described in a concept.

Spring transaction and database transaction

What is a transaction? A transaction is possible to access and update the database in a variety of program execution unit data items that are either fully executed or not completely executed.

Spring's transaction is a package of transactional database, to achieve the final nature or in the database, if the database does not support transactions, then, Spring's transaction has no effect
so that the underlying Spring transaction depends MySQL transaction, Spring is the use of the code level AOP implementations, when executing a transaction using TransactionInceptor to intercept and handle.
Published 964 original articles · won praise 11 · views 30000 +

Guess you like

Origin blog.csdn.net/xiaoyaGrace/article/details/105364013