Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the benefit of using reactive programming over ExecutorService?

If both are asynchronous in nature, then what's the use of using Reactive programming over ExecutorService in Java? In what ways reactive programming can be found effective as compared to ExecutorService?

like image 468
Vineeta Avatar asked Jul 10 '19 08:07

Vineeta


People also ask

What are the benefits of reactive programming?

Reactive programming is a design approach that uses asynchronous programming logic to handle real-time adjustments to typically static information. It provides an efficient mechanism — the use of automated data streams — for handling content modifications in response to user inquiries.

When should you use reactive programming?

One of the most common use-case for using RP is when you need handling of asynchronous data streams. Yet, this is a tricky question to answer because even a minuscule difference in the use-case might become a deciding factor in our choice.

Why is reactive programming faster?

One of the reasons why the Reactive Model is able to serve requests that fast is because it's offloading the task of “checking if an operation has completed” to the Operating System, which has an optimized way of doing that (kqueue/epoll on Linux for example) and thus avoiding the overhead of syscalls and userspace/ ...


1 Answers

Asynchronous programming usually includes some kinds of task interaction. Different kinds of asynchronous programming provide different kinds of task interaction.

ExecutorService executes submitted tasks as soon as there exists available processor, that is, it provides only simplest form of asynchronous programming, without task interaction at all.

Reactive programming provides channels to exchange messages with backpressure, which is quite advanced kind of task interaction. But under the hood, it still uses an ExecutorService.

like image 109
Alexei Kaigorodov Avatar answered Oct 07 '22 06:10

Alexei Kaigorodov