web123456

Java interview questions - real interview questions for common projects (real interview questions were asked)

1. What microservices does the project contain? What are you responsible for?

Log in to microservices, register microservices, search microservices, shopping cart microservices, order microservices, etc.


2. How did you deal with calling a third-party interface exception?

  1. Check if the timeout time has exceeded the set and check the network
  2. If the network is normal, go and see what the returned error code is

3. Are you doing common fault-tolerant processing for services?

Fuse, current limit, downgrade


4. The maximum request traffic is set to 1W, and a 2W request suddenly comes. How to deal with the extra 1W?

  1. The workque queue in the thread pool can make ten thousand requests queue
  2. Thread pool rejection strategy, directly rejection
  3. Queue some, reject some

5. What should I do if the shopping cart is synchronously redis. In the asynchronous MySQL scenario, mysql data cannot be written in?

  1. Use rabbitmq delay queue, and some dead letter queues
  2. It is also possible that the database concurrency is too high and cannot be processed.

6. How did you test it before the project went online?

We set up an internal environment on the company's intranet. Our microservices use two or three machines in total, and then we set up both the environment and microservices, so that multiple microservices can be run on one machine.


7、Have you ever used custom annotations? Tell me a scenario when you use it in development?

Authentication permissions, some need to log in, some do not need to log in, and use it with the interceptor


8. Have distributed locks been used?

I have indeed not used it in the project, but I have learned some knowledge that such optimistic locks, redis locks, and zookeeper locks are based on temporary order, so that the latter node can listen to the previous node, and the previous node will automatically acquire the lock if it is deleted.


9. Let me tell you how your microservice project was deployed?

Set up the environment and package the project on each server


10、How to solve the problem of multi-data source in spring framework? (How to maintain data source)

Configure in spring

We should make the following configuration in spring:

 xml code

 < bean id = "dynamicLoadBean" class = "" > bean >

 < bean id = "dataSource" class = "" >

 < property name = "dataSource" >

 < ref bean = "dataSource1" />

 property >

 bean >

 < bean id = "sessionFactory" class = "." >

 < property name = "dataSource" >

 < ref bean = "dataSource" />

 property >

 ......

 bean >

 The dataSource property should actually be defaultDataSource to be more precise, that is, the default data source that should be specified when spring starts and when the customer does not specify a data source.

Advantages of this program

First of all, this solution is completely solved under the framework of spring. The data source is still configured in the spring configuration file, and the sessionFactory still configures its dataSource property. It does not even know the change of dataSource. The only difference is that a MultiDataSource is added between the real dataSource and the sessionFactory .

Secondly, it is simple to implement and easy to maintain. Although I have said so much about this solution, it is actually all analysis. The only code we really need to write is MultiDataSource and SpObserver. The MultiDataSource class really needs to write only two methods: getDataSource() and getDataSource(sp), while the SpObserver class is simpler. The simpler the implementation, the smaller the possibility of errors and the higher the maintenance.

Finally, this solution can make single data sources compatible with multiple data sources. This solution does not affect the writing of BUS and DAO at all. If our project was developed when it was a single data source at the beginning and as the project progressed, it would be necessary to change to multiple data sources, then we only need to modify the spring configuration and modify the MVC layer a little to write the required data source name in the request, and the change is completed. If our project wants to change back to a single data source, we only need to simply modify the configuration file. This will add more flexibility to our projects.

Serial number Link address
1 Java Interview Questions: Redis Common Interview Questions (I was asked when I was actually interviewed)
2 Java Interview Questions: Spring Core Interview Questions (must be understood and memorized)
3 Java Interview Questions: Collection of Common Interview Questions
4 Java interview questions: MQ, RabbitMQ interview questions (must ask for interviews, the best version)
5 Java interview questions: Common interview questions for Mysql
6 Java interview questions: 15 common interview questions for threads, thread pools, and locks
7 Java interview questions: 5 common interview questions in jvm
8 Java Interview Questions: Custom Annotations Common Interview Questions
9 Java Interview Questions: 5 Common Interview Questions in Singleton Mode
10 Java Interview Questions: Nacos Common Interview Questions
11 Java Interview Questions: Elasticsearch Interview Raid
12 Java interview questions: Springboot common interview questions (I)
13 Java Interview Questions: SpringBoot Common Interview Questions (II)
14 Java interview questions: Common status codes for HTTP (I was asked about the actual interview)
15 Java interview questions: Real interview questions for common projects (real interview questions were asked)
16 Java interview questions: Common interview questions for projects (single sign-in, shopping cart)
17 Java Interview Questions: Applicable to 2-5 years of back-end development interview (I)
18 Java Interview Questions: Applicable to 2-5 years of back-end development interview (II)
19 Java Interview Questions: Applicable to 2-5 years of back-end development interview (III)
20 Java interview questions: Common interview questions for backend development in 2-5 years (four)
21 Java interview questions: 2-5 years of experience backend development interview record (5)
22 Java Interview Questions - Common Interview Questions for Backend Development in 2-5 years (VI)