preface

Recently in view of the Internet company interview asked knowledge points, summed up the Java programmer interview involves most of the interview questions and answers to share with you, I hope to help you review before the interview and find a good job, but also save you on the Internet to search for information time to learn.

Content covers: Java, MyBatis, ZooKeeper, Dubbo, Elasticsearch, Memcached, Redis, MySQL, Spring, SpringBoot, SpringCloud, RabbitMQ, Kafka, Linux and other technology stacks.

Full version Java interview questions address: Java backend questions integration

1. Why Dubbo?

With the further development of servitization, there are more and more services, and the invocation and dependency between services are more and more complex. Service-oriented Architecture (SOA) has been born, and a series of corresponding technologies have been derived. A service framework that encapsulates behavior such as service provision, service invocation, connection processing, communication protocol, serialization, service discovery, service routing, and log output. Thus a service governance framework for distributed systems emerged, and Dubbo was born.

2. What are the layers of the overall architectural design of Dubbo?

Interface Service layer: This layer is related to the business logic, and the corresponding interface and implementation configuration layer (Config) are designed according to the services of Provider and consumer: External configuration interface, with ServiceConfig and ReferenceConfig as the center of the service Proxy layer: The service interface transparent proxy generates the client Stub and server Skeleton of the service, with ServiceProxy as the center and ProxyFactory service Registry as the extension interface: Encapsulate the registration and discovery of service addresses, centering on the service URL, with extended interfaces as RegistryFactory, Registry, RegistryService routing layer (Cluster) : Encapsulate routing and load balancing for multiple providers and bridge registries centered on Invoker with extended interfaces for Cluster, Directory, Router, and LoadBlancce monitoring layer (Monitor) : RPC call count and call time monitoring, Statistics centric, extended interface for MonitorFactory, Monitor, and MonitorService Remote Call layer (Protocal) : Encapsulate RPC calls, based on Invocation and Result, with Protocal, Invoker and Exchange extensions. Encapsulate request response mode and turn synchronous to asynchronous. For Request and Response, the expansion interface is Exchanger, ExchangeChannel, ExchangeClient and ExchangeServer Transport: Abstract Mina and NetTY as a unified interface, Message centric, extended interfaces for Channel, Transporter, Client, Server and Codec data serialization layer (Serialize) : Reusable tools extend interfaces to Serialization, ObjectInput, ObjectOutput, and ThreadPool

3. What communication framework is used by default? Is there any other choice? The netty framework is also recommended by default, as is Mina.

The netty framework is also recommended by default, as is Mina.

4. Is the service invocation blocking?

It blocks by default and can be called asynchronously, if there is no return value. Dubbo is a non-blocking parallel invocation based on NIO. The client does not need to start multithreading to complete the parallel invocation of multiple remote services. Compared with multithreading, the overhead is relatively small, and asynchronous invocation will return a Future image.

5. What registry is generally used? Is there any other option?

Zookeeper, Redis, Multicast, and Simple registries are recommended, but not recommended.

What serialization framework is used by default, and what else do you know?

Hessian serialization is recommended, as well as Duddo, FastJson, and Java serialization.

7. What is the principle that service providers can achieve failure kick out?

Service failure Kicks out temporary zooKeeper-based nodes.

8. How does the launch of the service not affect the old version?

Adopt multi-version development, do not affect the old version.

9. How to solve the problem of long service invocation chain?

You can combine zipkin for distributed service tracking.

10. What are the core configurations?

11. What protocol does Dubbo recommend?

Dubbo :// (recommended) rmi:// hessian:// http://webService :// thrift:// memcached:// redis:// rest://

12. Can a service be directly connected with multiple registrations of the same service?

You can directly connect to a service point-to-point by modifying the configuration, or directly connect to a service through Telnet.

Draw a flow chart for service registration and discovery.

14. How many schemes are there for Dubbo cluster fault tolerance?

Dubbo service is degraded. What should I do if I try again?

Mock =”return NULL “can be set in dubbo: Reference. You can also change the mock value to true and implement a mock class in the same path as the interface, using the “interface name + mock” suffix. Then implement your own degradation logic in the Mock class

16. What are the problems encountered during the use of Dubbo?

The corresponding service cannot be found in the registry. Check if the service implementation class has added the @service annotation and cannot connect to the registry. Check if the corresponding test IP in the configuration file is correct

17, Dubbo Monitor implementation principle?

The Consumer goes through the Filter chain before making the call. When receiving a request, the provider goes through the Filter chain first and then performs actual business logic processing. By default, both consumer and provider filter chains have MonitorFilters. (1) MonitorFilter sends data to DubboMonitor. (2) DubboMonitor aggregates data (1 minute by default) and stores ConcurrentMap<Statistics. AtomicReference> statisticsMap, then use a single thread with 3 threads (thread name: The thread pool of DubboMonitorSendTimer calls SimpleMonitorService every 1min to iterate over statisticsMap data. SimpleMonitorService puts the aggregated data into BlockingQueue Queue (queue uppercase 100000) to reset the current Statistics AtomicReference (3) (4) SimpleMonitorService uses a background thread (thread name: DubboMonitorAsyncWriteLogThread) will be written to the file of data in the queue (this thread to write in the form of infinite loop) (5) SimpleMonitorService also use a contains one thread (thread name: The DubboMonitorTimer thread pool graphs the statistics in the file every 5 minutes

18. What design patterns does Dubbo use?

Dubbo framework uses a variety of design patterns during initialization and communication, which can flexibly control functions such as class loading and limit control. The factory mode Provider invokes the Export method of ServiceConfig when exporting the service. There is a field in ServiceConfig: private static final Protocol protocol =ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension(); There’s a lot of this code in Dubbo. This is also a factory pattern, except that the implementation class is fetched using the JDKSPI mechanism. The advantage of this implementation is that it is extensible, and to extend the implementation, you can simply add a file to the classpath, with zero code intrusion. In addition, Adaptive implementation, like the one above, can dynamically decide which implementation to call when calling, but because this implementation uses dynamic proxy, it will cause trouble in code debugging, and the implementation class actually called needs to be analyzed. Decorator pattern Dubbo makes heavy use of decorator pattern in both startup and invocation phases. In the case of Provider, the call chain is ProtocolFilterWrapper’s buildInvokerChain, which implements Filter with group= Provider. In order, the last call order is: EchoFilter -> ClassLoaderFilter -> GenericFilter -> ContextFilter ->ExecuteLimitFilter -> TraceFilter -> TimeoutFilter -> MonitorFilter ->ExceptionFilter More specifically, this is a mix of decorator and Responsibility chain patterns. For example, the function of EchoFilter is to determine whether it is an echo test request. If it is, the content is directly returned, which is a manifestation of the responsibility chain. Something like ClassLoaderFilter simply adds functionality to the main function, changing the ClassLoader of the current thread, which is a typical decorator pattern. Observer mode When Dubbo’s Provider is started, it interacts with the registry to register its own service and then subscribe to its own service. When subscribing, the Observer mode is used and a Listener is started. The registry periodically checks for service updates every five seconds. If there are updates, it sends a Notify message to the service provider. After receiving the notify message, the provider runs the notify method of NotifyListener and executes the listener method. The Adaptive implementation of the Dubbo class ExtensionLoader that extends JDK SPI is a typical dynamic proxy implementation. Dubbo needs flexible control of the implementation class, that is, at the call stage, it dynamically decides which implementation class to call according to the parameters, so the method of using the proxy class can achieve flexible call. Generated proxy class code is ExtensionLoader createAdaptiveExtensionClassCode method. The main logic of the proxy class is to get the value of the specified parameter in the URL parameter as the key to get the implementation class.

How is the Dubbo configuration file loaded into Spring?

When the Spring container is started, it reads some of Spring’s default schemas as well as Dubbo’s custom schemas. Each schema has its own NamespaceHandler. NamespaceHandler uses BeanDefinitionParser to parse configuration information and convert it to loaded bean objects!

What is the difference between Dubbo SPI and Java SPI?

The STANDARD SPI of the JDK SPIJDK will load all extension implementations at once. If there is an extension that takes time, but is not used, it is a waste of resources. So it’s not realistic to just want to load one implementation, DUBBO SPI

(1) To expand Dubbo, do not need to change the source of Dubbo

(2) lazy loading, you can load only the extension implementation you want to load at a time.

(3) Added support for extension points IOC and AOP, one extension point can directly setter injection of other extension points.

(4) Dubbo’s extension mechanism can well support third-party IoC containers, and Spring beans are supported by default.

21. Does Dubbo support distributed transactions?

When the Spring container is started, it reads some of Spring’s default schemas as well as Dubbo’s custom schemas. Each schema has its own NamespaceHandler. NamespaceHandler uses BeanDefinitionParser to parse configuration information and convert it to loaded bean objects!

22. Can Dubbo cache results?

The STANDARD SPI of the JDK SPIJDK will load all extension implementations at once. If there is an extension that takes time, but is not used, it is a waste of resources. Therefore, it is not realistic to load only one implementation of DUBBO SPI1. To extend DUBBO, there is no need to change the source code of DUBBO 2. Lazy loading, you can load only the extension implementation you want to load at one time. 3. Added support for extension points IOC and AOP, where one extension point can directly setter to inject other extension points. 3. Dubbo’s extension mechanism supports third-party IoC containers well, and Spring beans are supported by default.

23, service online how compatible with the old version?

You can transition to version, where multiple services of different versions are registered in the registry and services of different version numbers do not refer to each other. This is somewhat similar to the concept of service grouping.

24. What packages must Dubbo rely on?

Dubbo must rely on JDK, otherwise optional.

What does the Dubbo Telnet command do?

After dubbo service is released, we can use Telnet command to debug and manage. Telnet localhost 20880 // Press Enter to enter the Dubbo command mode. View the service list dubbo > lscom. Test. TestService dubbo > ls com. Test. TestServicecreatedeletequery, ls (list services and the methods), ls: Displays the service list. · Ls-L: Displays the detailed service information list. · ls XxxService: displays a list of service methods. · ls-l XxxService: Displays the service method details list.

Is Dubbo support service degraded?

Set mock=”return NULL “via dubbo: Reference. You can also change the mock value to true and implement a mock class in the same path as the interface, using the “interface name + mock” suffix. Then implement your own degradation logic in the Mock class

27. How does Dubbo stop gracefully?

Dubbo is implemented with JDK ShutdownHook for graceful shutdown, so if you use kill -9 PID or other forced shutdown commands, graceful shutdown will not be performed, only if you pass kill PID.

28. What’s the difference between Dubbo and Dubbox?

Dubbox is an extension project made by Dangdang based on Dubbo after Dubbo stopped maintenance, such as adding Restful service calls and updating open source components.