tags: spring boot java spring
The first step is to add @EnableAsync annotations to the startup class (must)
/**
* starting program
*
*/
@SpringBootApplication
@EnableAsync
public class RuoYiApplication
{
public static void main(String[] args)
{
}
}
The second step, in the controller, the method T (), remember that the asynchronous method cannot be called in the same type
@GetMapping("/list")
public void test01() throws Exception{
batchPaymentService.t();
System.out.println ("After executing");
}
In the third step, adding annotations @Async (method Void and Future (waiting for asynchronous execution) in the service method to be asynchronous in the service layer
@Async
public void t() throws InterruptedException {
System.out.println("1");
Thread.sleep(10000);
for (int i = 0; i < 100; i++) {
System.out.println(i);
}
log.info("ttt");
}
The results of the execution can be seen that the asynchronous (first printed the execution, and the asynchronous method is printed)

The project example has been uploaded to GitHub, visiblegithub project address。 Before explaining the asynchronous call, let's first look at the definition of synchronous call; synch...
SpringBoot asynchronous task @Async annotation (four) To write an interface, first call the proce() method, and then return a string to the browser: Write a business logic. Sleeping for 5 seconds in t...
Common high concurrent plan Asynchronous, peak -cutting valley Caches, the cache is relatively stable high -frequency hotspot data Parallel, shorten the business response time Optimize your business c...
Background development process, when a time-consuming operation is often required to open a thread to perform asynchronous operations, providing @Async notes in SpringBoot can make us more quickly usi...
inJavaApplications, the vast majority of cases are achieved through synchronous way interactive process; but when dealing with third-party systems to interact, likely to cause slow response to the sit...
Directly paste code Custom thread pool Asynchronous service Test program Output result, time is 5010 milliseconds, asynchronous execution is successful...
table of Contents Foreword No asynchronous execution, no @Async annotation Execute tasks asynchronously, when adding @Async annotations Foreword @Async is an asynchronous annotation, placed on the met...
Demand: The company projects require the user to fill in basic information, such as when the name and license plate number, he needs to be inserted over the previous data read together. Idea: Because ...
Why do you need an asynchronous task? 1. If a request is sent to the server (assuming: send mail or SMS notification or batch message to the batch), due to the large number of baseline users, i...
front end: Back-end control layer: Background service: Browser: http://localhost:8090/MyLab/rpc/async/asyncTest In the asyncTest method, a for loop in the service will be called. This for loop ...