![]() |
VOOZH | about |
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.
@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.
Let's Assume One example. This is a simple Java code that makes the User.
This is Synchronize method this method run with main thread.
We are Using @Async annotation and make method as asynchronized.
@EnableAsync this application shoud enabling synchronization.
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.