Ali was confused during the interview? Thread concurrency + MySQL + Spring is not clear! After reading this article, I won’t count as losing!

Multithreading and concurrency, MySQL, Spring and other questions are the most favorite questions for interviewers in Java technology interviews. Here, most of the important questions are listed from the perspective of the interview, but you should still have a firm grasp of the basics of Java to deal with future problems. The "soul torture" of the following major knowledge points can help you clear all the problems encountered in the interview!

PS: The length of the article is limited. In order not to affect the appreciation, these "multithreading, concurrency, MySQL, Spring" and other knowledge points learning materials can be directly

Hundred questions in Java concurrent programming interviews:

  1. Now there are three threads T1, T2, and T3. How do you ensure that T2 is executed after T1 is executed, and T3 is executed after T2 is executed?
    This thread question is usually asked in the first round or the phone interview stage, the purpose is to test whether you are familiar with the "join" method. This multi-threading problem is relatively simple and can be implemented with the join method

  2. What are the advantages of the Lock interface over synchronized blocks in Java?
    You need to implement an efficient cache, which allows multiple users to read, but only allows one user to write, in order to maintain its integrity, how would you implement it?
    The biggest advantage of the lock interface in multithreading and concurrent programming is that they provide locks for reading and writing respectively. It can satisfy you for writing high-performance data structures like ConcurrentHashMap and conditional blocking. Java thread interview questions will increasingly be asked based on the interviewer's answers. I strongly recommend that you read Locks carefully before you go to the multi-threaded interview, because it is currently a large number of client-side caches and transaction connection spaces used to build electronic transaction systems.

  3. The difference between wait and sleep methods in java?
    Java thread interview questions that are often asked in telephone interviews. The biggest difference is that wait releases the lock while waiting, while sleep always holds the lock. Wait is usually used for interaction between threads, sleep is usually used to suspend execution

  4. Implement blocking queue in Java.
    This is a relatively difficult multi-threaded interview question, which can achieve many purposes.
    First, it can detect whether the candidate can actually use Java threads to write programs;
    second, it can detect the candidate's understanding of concurrent scenarios, and you can ask many questions based on this. If he uses wait() and notify() methods to implement blocking queues, you can ask him to use the latest Java 5 concurrency classes to write it again.

  5. Write code in Java to solve the producer-consumer problem.
    It is similar to the above question, but this question is more classic. Sometimes the interview will ask the following questions. How to solve the producer-consumer problem in Java, of course, there are many solutions, I have shared a method to achieve a blocking queue. Sometimes they even ask how to realize the philosopher's meal problem.

  6. Using Java to program a program that will cause a deadlock, how would you solve it?
    This is my favorite Java thread interview question, because even though the deadlock problem is very common when writing multi-threaded concurrent programs, many candidates cannot write deadlock free code (deadlock free code?), they are struggling. Just tell them that you have N resources and N threads, and you need all the resources to complete an operation. For the sake of simplicity, n can be replaced with 2. The larger the data, the more complicated the problem will be. Get more information about deadlocks by avoiding deadlocks in Java

  7. What are atomic operations, and what are atomic operations in Java?
    Very simple java thread interview question, the next question is that you need to synchronize an atomic operation.

  8. What is the key to volatile in Java? How to use it? How is it different from the synchronized method in Java?
    Since Java 5 and the Java memory model changed, threading issues based on the volatile keyword have become more and more popular. You should be prepared to answer questions about how volatile variables ensure visibility in a concurrent environment

  9. What are race conditions? How do you discover and resolve competition?
    This is a question that appears in the advanced stage of multithreaded interviews. Most interviewers will ask about the competitive conditions you have encountered recently and how you resolved them. Sometimes they will write simple code and then let you detect race conditions in the code. You can refer to my previous article on Java race conditions. In my opinion this is one of the best java thread interview questions

  10. How will you use threaddump? How will you analyze Thread dump?
    In UNIX, you can use kill -3, and thread dump will print the log. In Windows, you can use "CTRL+Break". Very simple and professional threaded interview question, but if he asks you how to analyze it, it will be tricky.

Due to space reasons, I will not show all of them here. I have compiled these questions into pdf files and shared them for free to those in need. At the same time, it took a lot of time to organize them.

MySQL Soul Hundred Questions

  1. What is an index? An
    index is a data structure that can help us quickly search for data.

  2. What kind of data structure is the
    index ? The data structure of the index is related to the implementation of the specific storage engine. The most used indexes in MySQL include Hash index, B+ tree index, etc., and the default index implementation of the InnoDB storage engine we often use For: B+ tree index.

  3. What is the difference or pros and cons between Hash index and B+ tree?
    Hash index performs equivalent query faster (in general), but it cannot perform range query
    because after the hash function is used to build the index in the hash index, the order of the index It cannot be consistent with the original order and cannot support range queries. All nodes of the B+ tree follow (the left node is smaller than the parent node, the right node is larger than the parent node, and the multi-fork tree is similar), the natural support range
    hash index does not support the use of index For sorting, the principle is the same as above. The
    hash index does not support fuzzy query and the leftmost prefix matching of multi-column indexes. The principle is also because the hash function is unpredictable. The indexes of AAAA and AAAAB have no correlation

  4. As mentioned above, the B+ tree does not need to return to the table to query data when it meets the clustered index and the covering index. What is a clustered index?
    In the B+ tree index, the leaf node may store the current key value, or it may store the current The key value and the entire row of data are clustered indexes and non-clustered indexes. In InnoDB, only the primary key index is a clustered index. If there is no primary key, a unique key is selected to build a clustered index. If there is no unique key , Then a key is implicitly generated to build a clustered index.

  5. Will the non-clustered index always return to the table query?
    Not necessarily, this involves whether all the fields required by the query statement hit the index. If all the indexes are hit, then there is no need to perform the return table query.

  6. What are the factors that need to be considered
    when building an index ? When building an index, it is generally necessary to consider the frequency of use of the field. The field that is often used as a condition for query is more suitable. If you need to build a joint index, you also need to consider the joint index In the order. In addition, other aspects should also be considered, such as preventing too much pressure on the table. These are related to the actual table structure and query mode

  7. What is a joint index? Why do you need to pay attention to the order in a joint index?
    MySQL can use multiple fields to create an index at the same time, called a joint index. In a joint index, if you want to hit the index, you need to use one by one in the order of the fields when the index is created , Otherwise the index cannot be hit

  8. What is a transaction? A
    transaction is a series of operations that must conform to ACID characteristics. The most common understanding is: either all operations in a transaction succeed or all fail. But just this is not enough

  9. What is ACID? Can you elaborate on it?
    A=Atomicity Atomicity: As mentioned above, either all succeed or all fail. It is impossible to perform only a part of the operation.
    C=Consistency system (database) always starts from a consistent The state transfers to another consistent state, there will be no intermediate state. I=Isolation isolation: Generally speaking: a transaction is invisible to other transactions before it is fully committed. Note that the previous one is usually red , Means there are exceptions.
    D=Durability Durability: Once the transaction is committed, it will always be like this, even if the system crashes, it will not affect the result of the transaction.

  10. At the same time there are multiple transactions during what will happen?
    Concurrent multiple transactions are usually caused by the following questions:
    Dirty read: A transaction reads the contents B uncommitted transactions, and later B transaction was rolled back.
    Not Repeated reading: When setting transaction A to only read the committed part of transaction B, it will cause two queries in transaction A, and the results will be different, because transaction B has committed during this period.
    Phantom read: transaction A Read the contents of a range, while at the same time B transaction inserted a piece of data during this period. Cause "illusion".

Spring soul hundred questions

  1. Talk about your understanding of Spring IoC?
    IoC Inverse of Control The concept of inverse control. The operation of manually creating objects in the previous program is handed over to the Spring framework to implement, and the operation of creating objects is reversed to the Spring framework. The life cycle of the object is managed by Spring, and an object is obtained directly from Spring.

  2. Talk about your understanding of Spring DI?
    DI Dependency Injection Dependency Injection. When the Spring framework creates Bean objects, it dynamically injects dependent objects into the Bean component to achieve the injection of dependent objects.

  3. What is the difference between the BeanFactory interface and the ApplicationContext interface?
    ①. The ApplicationContext interface inherits the BeanFactory interface. The core factory of Spring is the BeanFactory. The BeanFactory adopts lazy loading. The Bean will be initialized when the Bean is first get.
    ②. ApplicationContext is an extension of BeanFactory, which can carry out internationalization processing, event transmission, Bean automatic assembly and various application layer Context implementations.
    Basically, ApplicationContext is used in development, Web ApplicationContext is used in Web projects, and BeanFactory is rarely used.

  4. Please introduce the Spring core classes you are familiar with, and explain what they do?
    ①. BeanFactory: Generate a new instance, which can realize the singleton mode
    ②. BeanWrapper: Provide unified get and set methods
    ③. ApplicationContext: Provide the implementation of the framework, including all the functions of BeanFactory.

  5. Introduce your understanding of Spring's affairs?
    A transaction is the smallest unit of work for database operations, and is a series of operations performed as a single logical unit of work; these operations are submitted to the system as a whole, either executed or not executed; a transaction is a set of indivisible operations (Working logic unit).

  6. Explain the AOP module
    AOP (Aspect-Oriented Programming) is a type of programming that increases the modularity of the program by separating cross-cutting concerns. AOP adds functionality to existing code without modifying the existing code. This is the most important capability of AOP.

  7. What are the notification types of Spring, please briefly introduce?
    There are 5 types of Spring notifications: pre-notification, surrounding notification, post-notification, exception notification, and final notification.
    ①. Before advice: The advice executed before the target method is executed. A notice executed before a join point, but this notice cannot prevent execution before the join point (unless it throws an exception).
    ②. Around Advice: Notice that additional code can be executed before and after the execution of the target method. You can also choose whether to continue the execution of the connection points or directly return their own return value or throw an exception to end the execution.
    ③. After (finally) advice: After the target method is executed (when a connection point exits), the notification (regardless of normal return or abnormal exit) is executed.
    ④. After throwing advice: The advice executed when the method throws an exception and exits.
    ⑤. Final advice (After returning advice): Notice executed after a certain join point (join point) is completed normally: for example, a method does not throw any exception and returns normally.

  8. What are the usage scenarios of Spring notification types?

  1. Please introduce your understanding of Spring Beans?
    ①. Spring Beans are Java objects that are instantiated, assembled and managed by the Spring container
    ②. Spring Beans will be instantiated by the Spring container automatically @bean objects
    ③. Spring framework definition Beans are defaulted as singleton, and can also be configured as multiple instances

  2. What are the advantages of Spring?
    ①. Provides the ability of inversion of control and hands over the creation of objects to Spring, which reduces the coupling and intrusiveness of the code.
    ②. Spring is POJO programming, which improves the sustainable construction and testability
    ③. Spring is Open source and free
    ④. Convenient integration of various excellent frameworks

At last

Share another wave of my Java topic interview questions for free + detailed video learning + Java advanced learning books

Reference study materials: Java core technical notes

JVM, collection, HTTP network, multi-threaded concurrency, JAVA foundation, Spring, microservice, Zookeeper, Kafka, RabbitMQ, Hbase, message middleware, MongoDB, design pattern, load balancing, database, consistent hash, algorithm, data structure , Encryption algorithm, distributed cache, Netty, Linux, Tomcat, Nginx, Redis, etc.

Sorting out various learning books: "Redis combat", "Practical microservices using SpringCloud and Docker", "Spring Boot combat", "Deep Analysis of Spring Source Code", "Distributed Service Framework Principles and Practices", etc.

Sorting out various interview questions: BAT interview frequently asked questions 80, Dubbo, Netty, JVM, concurrency, Tomcat, MySQL, Spring, Redis, MongoDB, distributed, microservices, locks, Nginx, performance optimization, Memcached, etc.

The focus of this article is whether you have gained and grown, and the rest is not important. I hope readers can keep this in mind.

 

 

 


 

Guess you like

Origin blog.csdn.net/AMSRY/article/details/108867593