what is the difference between RxJava and Bolts?
Asked Answered
A

3

7

I have done research on this, and I know that RXJava is using the observable pattern, and Bolts is relying on an executor. What framework would be good for handling tasks that need to be done in sequences?

I've heard of using singleExecutors, queues, chaining asynctasks, and these two frameworks. I've seen more people using bolts vs. rxjava but am curious to hear about peoples experiences between the two.

Thanks!

Atrioventricular answered 18/7, 2016 at 16:33 Comment(0)
O
19

I've used both in different projects and have done a migration from Bolts to RxJava. The simple answer to your question

What framework would be good for handling tasks that need to be done in sequences?

Is that you could easily use either framework to do this. They both:

  • Allow tasks to be chained one after another
  • Enable the executor, etc to be specified for each task
  • Allow errors to be captured and dealt with at a convenient time

However that is where Bolts functionality ends pretty much whilst RxJava just keeps on giving. The real power of RxJava lies in its operators which amongst other things allow you to transform, combine & filter data.

The learning curve for both frameworks is steep, RxJava is steeper...but it is considerably more powerful.

As an aside the method counts for the two libraries are

RxJava - 4605
Bolts  - 479
Occasion answered 18/7, 2016 at 21:19 Comment(2)
Thanks!! was it an easy transition from bolts to rxjava? any pitfalls i might run into?Atrioventricular
There's a lot of pitfalls you will run into in rx-java. It's very powerful and expressive. Personally the cache operator didn't do exactly what I would have expected. Also, it's difficult to write Observables and Operators that respect backpressure.Pickens
H
9

Jahnold gave a great overview and I just wanted to add a little more info:

First off, both Bolts and RxJava are Java implementations of Microsoft's asynchronous programming models: Bolts = Task Parallelization Library and RxJava = Reactive Extensions. They also both allow chaining and thread switching very easily (background <-> main thread).

The best way to compare Bolts/TPL to RxJava/Rx is that Bolts is for asynchronous single values (promises) and RxJava is for asynchronous lists of values (streams).

  • So Bolts would be good for background work that returns a single value such as general network requests, reading files off disk, etc and
  • RxJava would be good for things that return multiple values such as subscribing to GPS coordinates, onClick events, etc.

So to better answer your question:

What framework would be good for handling tasks that need to be done in sequences?

I'd have to ask another: do you intend for your work to be single result or multiple results?

Hygroscopic answered 19/7, 2016 at 18:36 Comment(3)
it would be single results for some requests and multiple for others... sorry i know that doesn't help.Atrioventricular
There's no reason why you can't use both!Hygroscopic
@GrantlandChew Although your answer is not biased toward Bolts, it would have been good writing a disclaimer line. (Very good answer btw. I was in same doubt and will go with Bolts).Scuttlebutt
C
1

These two libraries solve two different problems.

Bolts

Bolts simplifies asynchronous programming by transparently pushing code to a background thread. Bolts also spends a good deal of effort attempting to reduce unsightly code nesting that produces a nested pyramid like format.

Therefore, if you are specifically looking to deal with async (multi-threading) issues, Bolts is on of the more robust solutions. Bolts is also effective at relieving code nesting and callback boilerplate and is probably a great solution for just trying to relieve callback issues.

RxJava

RxJava is specifically designed to support a reactive programming paradigm. Reactive programming is an alternative to imperative programming in Java. You might choose to move to a reactive programming paradigm for various reasons - of which there are many. If you want migrate your code to the reactive programming model, or you want to use reactive in your greenfield projects, consider using RxJava - the de facto reactive standard in the Java world.

Reactive does also solve the asynchronous programming problem, as well reduce callback boilerplate via generics. But it should not be used just to solve those problems. For example, Bolts ability to solve the nested pyramid code structure makes it a more viable solution for async programming. On the other hand, if you are using reactive via RxJava, async problems are already solved, so there is no point bringing in Bolts.

Collegian answered 10/12, 2017 at 15:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.