2 Basic Framework
2.1 Spring/Springboot/for SpringMVC
1. The difference between @autowired and @resouce
-@autoWired by default assembs by type (this annotation is for property Spring). By default, the dependent object must exist. To allow null values, you can set its required property to false, as in: @autoWired (required=false), which can be used with the @qualifier annotation if we want to use name assemblies; -@resource (this annotation belongs to J2EE), which is assembled by name by default. The name can be specified by the name attribute. If the name attribute is not specified, when the annotation is written on a field, the installation name lookup is performed by default. Assemble by type when no bean matching the name can be found. Note, however, that if the name attribute is specified, it will only be assembled by name; For example: RedisTemplate's parent delegate problemCopy the code
2. Starter principle of Springboot
Principle: Using the starter to implement automatic configuration requires only two conditions: Maven dependency and configuration file. This section describes the process of implementing automatic configuration using the starter. The starter jar contains the resources/ meta-INF /spring.factories file, and the starter jar contains the resources/ meta-INF /spring.factories file. Find the classes that need to be configured automatically. - The configuration is as follows: org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ com.ouyanglol.starterdemo.config.DemoAutoConfiguration - Notes used: @configuration indicates a Configuration file, The annotated class will become a bean configuration class @conditionAlonClass automatically configured when the class is found in classpath @conditionalonBean automatically configured when the class is found in classpath @ EnableConfigurationProperties gives effect to @ ConfigurationProperties annotation @ AutoConfigureAfter completion of automatic configuration instantiate the bean reference blog: https://blog.csdn.net/Mr_OOO/article/details/89477948Copy the code
Level-1 cache Session Level-2 cache Mapper has a data delay
1. What are BIO, NIO and AIO, their differences and applicable scenarios?
1. Concept: -bio: Synchronous blocking, the server implementation mode is one connection one thread, that is, when the client has a connection request, the server needs to start a thread to process, if the connection does not do anything, it will cause unnecessary thread overhead, of course, can be improved through the thread pool mechanism. - NIO: synchronously non-blocking. The server implements one request one thread, that is, all connection requests sent by the client are registered with the multiplexer. The multiplexer starts a thread to process the connection only after polling for I/O requests. - AIO: asynchronous non-blocking. The server implements a valid request to one thread. The CLIENT's I/O request is completed by the OS and then notified the server application to start the thread for processing. Application scenario: the -BIO mode applies to architectures with a small number of fixed connections. This mode has high requirements on server resources, and the concurrency is limited to applications. The program is intuitive, simple and easy to understand. - NIO applies to architectures with a large number of connections and relatively short connections (light operation), such as chat servers. Concurrency is limited to applications and programming is complex. JDK1.4 supports NIO. - AIO mode is used for architectures with a large number of connections and long connections (heavy operations), such as photo album server. The OS is fully invoked to participate in concurrent operations, and the programming is complicated, which is supported in JDK7.Copy the code
2. What is Netty? How does it work? Core components? The advantages and disadvantages?
1. What is it? - Netty is a NIO-based client-server framework, which can be used to develop network applications quickly and easily. It greatly simplifies and optimizes network programming such as TCP and UDP socket servers, and is even better in many areas, including performance and security. Supports multiple protocols such as FTP, SMTP, HTTP and a variety of binary and text-based traditional protocols. - Many open source projects use Netty such as Dubbo, RocketMQ, Elasticsearch, gRPC, etc. 1. Channel-channel interface is a Netty abstract class for network operations. It includes basic I/O operations, such as bind(), connect(), read(), write(), etc. - common Channel interface implementation classes are NioServerSocketChannel (server) and NioSocketChannel (client), These channels correspond to the concepts of ServerSocket and Socket in the BIO programming model. 2.EventLoop - EventLoop defines Netty's core abstraction for handling events that occur during the lifetime of a connection. In a nutshell, the main purpose of EventLoop is to listen for network events and call the event handler for related I/O operations. - What is the direct connection between Channel and EventLoop? Channel is an abstract class for Netty network operations (such as reading and writing operations). EventLoop processes the Channel processing I/O operations registered on Channel. 3.ChannelFuture Netty is asynchronous and non-blocking. All I/O operations are asynchronous. Therefore, we can't immediately know whether the operation was successful or not. However, you can register a ChannelFutureListener with the addListener() method of the ChannelFuture interface. When the operation succeeds or fails, the listener will automatically return the result. Also, you can retrieve the associated channel through ChannelFuture's Channel () method. Alternatively, we can make asynchronous operations synchronous through the sync() method of the ChannelFuture interface. 4.ChannelHandler and ChannelPipeline - ChannelHandler is the specific handler of the message. He handles reads and writes, client connections, and so on. - ChannelPipeline is a chain of ChannelHandlers, providing a container and defining apis for propagating the inbound and outbound event streams along the chain. When a Channel is created, it is automatically assigned to its own ChannelPipeline. - We can add one or more ChannelHandlers on ChannelPipeline via the addLast() method, since a single data or event may be handled by multiple handlers. When one ChannelHandler has finished processing the data is passed to the next ChannelHandler.Copy the code