![]() |
Synchronization means every process or thread should be Synchronized together. It means executing process by process that’s we can say Synchronization. This is used when one task is complete and only then does another task want to come and be executed. so It looks like there are some limitations. That’s why asynchronization comes into the picture. The Asynchronization process means We are making a different thread for the same processing. Process or thread does not need to wait for someone to execute. This is The Asynchronization process. Benefits of @Async Annotation@Async annotation is used when you wanna make any method asynchronize. Annotating a method of a bean with @Async will make it execute in a separate thread. In other words, the caller will not wait for the completion of the called method.
Example ProjectLet’s Assume One example. This is a simple Java code that makes the User. Java
This is Synchronize method this method run with main thread. Java
We are Using @Async annotation and make method as asynchronized. Java
@EnableAsync this application shoud enabling synchronization. Java
Output:Now, we can see user save task and notification task going into different thread. because of implementing async annotations. It means notification task executed according that required time not need wait for previous task. |
Reffered: https://www.geeksforgeeks.org
Advance Java |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |