In Java applications, most of the interactive processing is achieved by means of synchronization. However, when dealing with the interaction with third party systems, it is easy to cause slow response. Most of the previous use of multithreading to complete such tasks, in fact, after Spring 3.x, @async has been built to solve this problem perfectly.
Two comments: @enableaysnc, @aysnc
First let's look at operations without asynchronous interfaces
Start the server: We can see that the page waits three seconds before executing the desired result
After three seconds:
Here we add the synchronization operation (easy to do with just two annotations) :
Don't forget to enable asynchronous annotations on the launcher, otherwise asynchronous annotations won't work
Here we can see that asynchrony can start successfully
Second, scheduled tasks
There are often scheduled tasks that need to be performed during project development, such as analyzing logs from the previous day at dawn every day. Spring provides us with a way to perform task scheduling asynchronously, providing TaskExecutor and TaskScheduler interfaces.
Two comments: @enablescheduling, @scheduled
Enable annotation-based scheduled tasks
View console print
Source code address: github.com/839022478/s...