1. Why does redis read so fast?
1. Based entirely on memory, most of the requests are pure memory operations, very fast. Data is stored in memory, similar to HashMap. The advantage of HashMap is that the time complexity of search and operation is O(1);
2. Single thread is used to avoid unnecessary context switching and competition conditions, there is no switching caused by multi-process or multi-thread to consume CPU, no need to consider various lock issues, there is no lock release operation, no Performance consumption due to possible deadlock;
3. Use multi-channel I/O multiplexing model, non-blocking IO.
2. What are the injection methods of springBean?
Constructor injection: Constructor injection refers to injecting properties or objects in the constructor to achieve dependency injection.
SET method injection: Set method injection is to implement dependency injection of attributes or objects by implementing get and set methods in the class.
Annotation injection: @Autowired annotation can realize automatic assembly, as long as the annotation is marked on the corresponding attribute, but the @Autowired annotation is only injected according to byType. The @Resource annotation can realize automatic assembly. It has two important attributes: name and type. The name attribute is resolved to the name of the bean, and the type attribute is resolved to the type of the bean. So if the name attribute is used, the automatic injection strategy of byName is used, and the automatic injection strategy of byType is used if the type attribute is used. If neither the name nor the type attribute is specified, then the byName automatic injection strategy will be used through the reflection mechanism. The @Autowired annotation has the same effect as the @Resource annotation, except that @Autowired is injected according to byType. If @Autowired wants to use the name, it can be used in conjunction with the @Qualifier annotation.
3. What are the dynamic sql tags of mybatis?
IF tag: Sometimes we have a lot of conditional queries during development, and we can fill in these conditions or not. At this time, we can use IF tags to solve them.
Trim tag: trim can help us complete the extra and or or, where tags that cannot be solved later, and can also be used to cut strings and so on.
Choose: It is similar to the case when function. It will only go one type. No matter how many of the when conditions are met, only the first one will be taken. If all the conditions of when are not met, the otherwise will be taken.
foreach tag: the meaning of foreach loop traversal, which can generally be used for query or batch adding functions.
4. What is the difference between BIO, NIO and AIO?
BIO: Block IO Synchronous blocking IO is the traditional IO we usually use. It is characterized by its simple mode and convenient use, and low concurrent processing capability.
NIO: New IO synchronous non-blocking IO is an upgrade of traditional IO. The client and server communicate through Channel to achieve multiplexing.
AIO: Asynchronous IO is an upgrade of NIO, also called NIO2, which implements asynchronous non-blocking IO. The operation of asynchronous IO is based on events and callback mechanisms.
5. What is the difference between Hashmap and hashtable?
1. HashMap is not thread-safe, HashTable is thread-safe.
2. Both the keys and values of HashMap are allowed to have null values, but HashTable does not.
3. Because of thread safety issues, HashMap is more efficient than HashTable.
4. Hashtable is synchronous, but HashMap is not. Therefore, HashMap is more suitable for single-threaded environment, while Hashtable is suitable for multi-threaded environment. Generally, it is not recommended to use HashTable now. ① HashTable is a legacy class, and many internal implementations are not optimized and redundant. ②Even in a multi-threaded environment, there is now a synchronous ConcurrentHashMap instead. There is no need to use HashTable because it is multi-threaded.
6. What are the core parameters of the thread pool?
corePoolSize: the size of the core thread pool
maximumPoolSize: the maximum number of threads that the thread pool can create
keepAliveTime: idle thread survival time
unit: time unit, specify the time unit for keepAliveTime
workQueue: blocking queue, blocking queue for saving tasks
threadFactory: creating threads Engineering
handler: saturation strategy (rejection strategy)
7. The realization principle of database index?
An index is a structure that sorts the values of one or more columns in a database table (for example, the name column of the employee table). If you want to find a specific employee by his or her last name, the index helps to obtain information faster than searching all rows in the table.
For example, such a query: select * from table1 where id=10000. If there is no index, you must traverse the entire table until the row with ID equal to 10000 is found; after having an index (must be an index established on the ID column), you can search in the index. Since the index is optimized by a certain algorithm, the number of searches is much less. It can be seen that the index is used for positioning.
8. How many people are in your project?
This is just an example!
According to the difficulty of the project business, the cycle, etc., the personnel will be different, so it can be combined with your own project situation.
9. How is Dubbo used in your project?
dubbo is mainly used to implement service calls between different systems in our project. Because our project is divided into different systems according to different functions, and according to the three-tier architecture, it is divided into different services, among which the control layer in the three-tier architecture As the consumer of the service, the business layer and the persistence layer jointly act as the publisher of the service. This architecture realizes the service-oriented system, improves the development efficiency, and realizes the decoupling of the business.
Through the integration of dubbo and spring, the whole spring configuration method is adopted in the project. Only spring is needed to load the configuration of dubbo to complete the service release and invocation. We mainly expose the service through the <dubbo:service> tag on the exposed side of the service, and reference the service through the <dubbo:reference> tag on the consumer side of the service. The registry center we use is zookeeper, which manages and manages the URL of the service. Configuration.
10. What protocol does Dubbo support? What are the differences between these agreements? What protocol does your project use?
Dubbo supports Dubbo protocol, RMI protocol, hessian protocol, Http protocol, etc.
Dubbo protocol: default protocol, single long connection and NIO asynchronous communication, thread pool concurrent processing request, can reduce handshake and increase concurrency efficiency, use Hession binary serialization, better performance, recommended.
It is mainly used for incoming and outgoing parameter data packets that are small (recommended less than 100K), and there are more consumers than providers. Because it is a single connection, try not to transfer large files.
RMI protocol: Adopt JDK standard RMI protocol (based on TCP protocol), blocking short connection, JDK standard serialization method, and synchronous communication. Applicable to similar numbers of consumers and providers, and transferable files. The test found that occasionally the connection fails and the Stub needs to be rebuilt.
Hessian protocol: using http communication, using Servlet to expose services, multi-connection and short-connection synchronous transmission mode, using Hession's binary serialization, suitable for more providers than consumers.
The default Dubbo protocol is used in our project (the other two are simple to know), because our project is mainly characterized by large concurrency and more consumers than providers.
11. What problems have you encountered while using Duubo?
(1) Serialization and deserialization exceptions: When the
service is called and the message fails to be sent, usually the incoming and outgoing parameters of the interface method are newly added extension classes, and the serialization interface is not implemented;
B service remotely calls A service , The return value is the C object, and the result of the breakpoint A service return value object C has a value, but the C object remotely obtained by the B service is null;
(2) Service call problem Is the
service provider operating normally? (This piece may involve the banning of the called service) Is
the registered center connected to the correct one? (Sometimes it involves the grouping of the registration center) Is the
corresponding service provider registered in the registration center?
(3) Invoking the version problem (adding the service version number and the consumer service version number during the development process)
When encountering multiple environments (development, testing, online), multiple versions (app, PC), a service It may not meet our needs, because the definition of the version number of the service can pave the way for the iterative upgrade of our later versions.
The whole process will encounter various problems, and these are basically technical problems.