Asynchronous methods using @Async annotation (Spring)
Let’s imagine that you need to call a time-consuming service method from a controller and its result can be postponed. For example, it can import a huge number of records to a database and you can’t force the client to wait minutes/hours for a response. In such a case, it makes sense to make such a method asynchronous, i.e. a separate thread will be created to process the task, but the controller will immediately return to the user. Spring can easily help to configure asynchronous methods using @Async annotation.