Home > database >  Difference between @Async and executor
Difference between @Async and executor

Time:06-09

I can't find any reason for using executor instead of @Async Spring annotation. Can someone explain me what is the difference between @Async and executors?

CodePudding user response:

Executors are more complex to use, but offer a lot of flexibility on how the function is run. For example, a ThreadPoolExecutor has a queue of the work it needs to do. If that queue is full, it can force the caller to run the work to keep the queue from overflowing.

@Async is designed to be simpler to use, but takes aways a lot of the control you have in how the execution happens. Also, the code becomes Spring specific, so it wouldn't be appropriate to use in a more widely distributed library.

  • Related