notes
3, SpringBoot2.x combat asynchronous tasks (Core Knowledge)
Description: to explain what is asynchronous tasks, the development and use of asynchronous task combat SpringBoot2.x
1, what is the use of asynchronous tasks and scenarios: for processing log, send email, SMS ...... etc.
Order Interface -> 100 check Stock
balance check 150
wind control user 100
....
2, which started using @EnableAsync based annotation opening function, automatic scanning
3, the class definition of asynchronous tasks using the container assembly is scanned mark @Component , together with the asynchronous method @Async
Precautions:
1) put the package into the class asynchronous task, can not be directly written to the Controller
2) increasing the Future <String> return results AsyncResult <String> ( "task execution is complete");
3) If Analyzing the results need to get all of the required task.isDone ()
. 4, by way of injection, the injection controller which, if before and after the test to the difference between the synchronous put Async commented
Start
springboot integrated asynchronous tasks
create asynchronous tasks like
creating three task
the method is marked as asynchronous tasks. Use @Async annotations
may be labeled in the above methods and classes
in the class also labeled asynchronous type
testing
Future
To get the result with the future. Judgment asynchronous execution is complete.
Modify synchronization
The notes of this class no. It is a synchronized class