Вопрос

What is the difference between @Async annotated method and Reactor set to use thread pool of the same size. Is there any advantage to one of this methods and what it would be? For my use, I do not care to return any value with the asynced method.

Это было полезно?

Решение

The most obvious difference is that Reactor doesn't crosscut @Async annotated methods and implicitly submit events to a Reactor. If you're using the Reactor @Selector annotation on beans then you're getting the opposite of what you would with @Async: an event handler, not an event publisher.

With that said, there is some support in Reactor for @Async-style event publishing through the DynamicReactorFactory. It uses an interface instead of an annotation, but the concept is similar.

Regarding "advantages" to using one or the other: it really depends on what other things you're doing in your application and whether or not you're using Reactor in a more general sense. Reactor isn't designed to be a thread pool replacement. The ThreadPoolExecutorDispatcher in Reactor just uses a plain ThreadPoolExecutor underneath. The advantages to using Reactor in that scenario come from the optimized event publishing used in Reactor versus creating new Callables and Runnables all the time, as well as using Reactor's Stream and Promise API to handle asynchronous execution.

Looked at from the API prespective, there is a distinct and measurable advantage to using Reactor over a plain TaskExecutor for background jobs.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top