How is the interview recently? Have you been asked about asynchronous programming again? You must read this Java asynchronous programming notes (including Go language) compiled by the great god

Generally, Java developers like to use synchronous code to write programs, because this request/response method is relatively simple and more in line with programmers’ thinking habits; this approach is good until the system has a performance bottleneck. When using synchronous programming, since each thread can only initiate one request at the same time and wait for the return synchronously, in order to improve system performance, we need to introduce more threads to achieve parallel processing. However, when accessing shared resources under multiple threads, resource contention and concurrency problems will inevitably be introduced; in addition, the number of threads is limited at the operating system level, and it is impossible to increase the number of threads infinitely to provide system performance; and , The use of synchronous blocking programming will also waste resources. For example, when a network IO request is initiated, the calling thread will be in a state of synchronous blocking waiting for the response result, and at this time the calling thread can obviously do other things, and wait for the network IO response result to return Process the results later.

It can be seen that parallel programming by increasing the number of threads in a stand-alone system is not a "magic bullet". By writing asynchronous, non-blocking code, you can use the same underlying resources to switch execution to another active task, and then return to the current thread to continue processing after the asynchronous processing is completed, thereby improving system performance.

Asynchronous programming is a method that allows programs to run in parallel. It allows a unit of work in the program to run independently of the main application thread, and after the work unit is finished, the main application thread will be notified of its running result or Reason for failure. Using asynchronous programming can improve application performance and responsiveness.

For example, when the calling thread initiates a network IO request in an asynchronous manner, the calling thread will not synchronously block and wait for the response result, but after the request context is saved in the memory, it will immediately return to do other things, and then use the IO after the network IO response result is returned. The thread notifies the business thread that the response result has been returned, and the business thread processes the result. It can be seen that the asynchronous call method improves the utilization of threads, allowing the system to have more thread resources to handle more requests. For example, in a mobile application, after the user operates the mobile device screen to initiate a request, if it is synchronously waiting for the background server to return the result, when the background service operation is very time-consuming, it will cause the user to see the mobile device screen freezing (always in the request processing In), the user cannot operate other functions of the mobile device before the result is returned, which is very bad for the user experience. When using asynchronous programming, when a request is initiated, the calling thread will return immediately, and the specific return result will be rendered asynchronously through the UI thread, and the user can use other functions of the mobile device during this period.

This study note shared today is a top tutorial note on Java asynchronous programming!

Due to the excessive content of the notes, only part of the content can be shown below for everyone. The free way to obtain the full Blu-ray version is at the end of the article!

Detailed chapter list

The most necessary technology in 2020: Java asynchronous programming Blu-ray notes (including Go language)

 

The most necessary technology in 2020: Java asynchronous programming Blu-ray notes (including Go language)

 

The most necessary technology in 2020: Java asynchronous programming Blu-ray notes (including Go language)

 

Chapter 1 Understanding Asynchronous Programming

This chapter mainly introduces the concept and function of asynchronous programming, the scenarios of asynchronous programming in Java, and what technologies should be used to implement different asynchronous programming scenarios.

The most necessary technology in 2020: Java asynchronous programming Blu-ray notes (including Go language)

 

Chapter 2 Explicit use of threads and thread pools to achieve asynchronous programming

This chapter mainly discusses how to explicitly use threads and thread pools to achieve asynchronous programming. This includes how to explicitly use threads to achieve asynchronous programming and the shortcomings of using thread programming, how to explicitly use thread pools to achieve asynchronous programming and the principle of thread pool implementation.

The most necessary technology in 2020: Java asynchronous programming Blu-ray notes (including Go language)

 

Chapter 3 Implementation of Asynchronous Programming Based on Future in JDK

This chapter mainly explains how to use Future in JDK to implement asynchronous programming, which includes how to use FutureTask to implement asynchronous programming and its internal implementation principles; how to use CompletableFuture to implement asynchronous programming and its internal implementation principles, and how to combine CompletableFuture and JDK Stream perfectly.

The most necessary technology in 2020: Java asynchronous programming Blu-ray notes (including Go language)

 

Chapter 4 Asynchronous Execution in the Spring Framework

In the Spring Framework, the TaskExecutor and TaskScheduler interfaces are used to provide abstractions for asynchronous execution and task scheduling. In this chapter, we focus on how to implement asynchronous processing based on the annotation @Asyne supported by TaskExecutor.

The most necessary technology in 2020: Java asynchronous programming Blu-ray notes (including Go language)

 

Chapter 5 Asynchronous Programming Based on Reactive Programming

This chapter mainly explains how to use reactive programming to achieve asynchronous programming, what it contains is reactive programming, why reactive programming is needed, what are the characteristics and values ​​of reactive programming, and how to realize asynchronous programming based on reactive programming library RxJava and Reactor .

The most necessary technology in 2020: Java asynchronous programming Blu-ray notes (including Go language)

 

Chapter 6 Asynchronous non-blocking processing of Web Servlet

This chapter mainly discusses the synchronous processing model and shortcomings before the Servlet3.0 specification, the asynchronous processing capabilities provided by the Servlet3.0 specification and the non-blocking I0 capabilities provided by the Servlet3.1 specification, as well as the asynchronous processing capabilities provided in Spring MVC.

The most necessary technology in 2020: Java asynchronous programming Blu-ray notes (including Go language)

 

Chapter 7 Asynchronous non-blocking processing of Spring WebFlux

This chapter mainly explains the new WebFlux technology stack introduced in Spring Framework 5.0, and introduces its value and significance, concurrency model and applicable scenarios, how to implement asynchronous programming based on WebFlux, and its internal implementation principles.

The most necessary technology in 2020: Java asynchronous programming Blu-ray notes (including Go language)

 

Chapter 8 High-performance asynchronous programming framework and middleware

This chapter mainly introduces some high-performance asynchronous programming frameworks and middleware, including asynchronous, event-driven network programming framework-Netty; high-performance RPC framework-Apache Dubbo; high-performance inter-thread messaging library-Disruptor; asynchronous, distributed, Akka based on message-driven framework; Apache RocketMQ, a high-performance distributed messaging framework.

The most necessary technology in 2020: Java asynchronous programming Blu-ray notes (including Go language)

 

Chapter 9 Asynchronous Programming Capabilities of Go Language

This chapter mainly explains the asynchronous programming capabilities of the Go language, which includes the threading model of the Go language, and how to use the primitive goroutine and channel to implement asynchronous programming. Finally, a pipeline supporting back pressure and asynchronous programming is constructed based on the goroutine and channel.

The most necessary technology in 2020: Java asynchronous programming Blu-ray notes (including Go language)

 

Those who need the Blu-ray version of Java asynchronous programming notes can receive it for free by adding the assistant VX below!

 

Guess you like

Origin blog.csdn.net/GYHYCX/article/details/109323259