“The thing is, non blocking communication in classic, imperative code can quickly turn into a unmaintainable swamp of threads and callbacks.” Frank Lyaruu is talking about non-blocking goodness that doesn’t trash your code at Voxxed Days Athens. We asked him when you’d need non-blocking code.

 

What are the situations where you need non-blocking code?

Whenever you can not afford to have a thread wait for something else to happen. For example, if I read a file from disc using blocking code, from the moment I request the data and I get that data, my thread is just sitting there doing nothing. Even if it only takes a few milliseconds, a single thread could have done SO MUCH in that time.

So, code that has a lot of I/O and networking code, and that makes it really relevant to micro service architectures.

What is Reactive Functional programming? How is it different from plain ‘Functional’ programming?

The thing reactive programming adds is about thinking about a program as a ‘pipeline’ of operations that process a stream of events. In a procedural (‘OO’) program, you think of a program as a series of instructions or method calls after another, that get called in sequence by a thread.
The way I usually explain it is that in procedural programming there is a ‘static’ piece of code, and a thread ‘moves’ through it, calling methods, branching based on if-then-else, looping, etcetera. In a reactive setting, you define a ‘pipeline’ that processes events, and using functional constructs like filters and maps to transform the data items.

Is it possible to do both Reactive Functional programming, and OO programming in the same project? Or as developers, should you pick one or the other?

Definitely, both coexist quite peacefully, for the vast majority of projects I guess there are parts where reactive works better and parts where OO works fine, it makes no sense to me to force one or the other just because you’ve made a ‘religious’ decision at the start of a project.

What are the benefits to using the RxJava library in a project?

Even though reactive programming can be a quite profound shift from procedural programming, RxJava is a surprisingly low-key library. It is not a framework, it has no dependencies, it is just a jar you can add. It does not change how your existing code works, it just opens a door to use a new way of looking at a problem. If you have a project that works fine for 99%, but for the last 1% you need some reactive code, it is a very easy step to take, and you can leave everything that is fine the way it is.

 

For more, see Frank’s talk at Voxxed Days Athens:

Parthenon at night on Acropolis at Athens Greece

Conquering non blocking code with RxJava

Profile photo of Katharine
About The Author
- Katharine is a Java developer by trade, turned Community & Content Manager for Voxxed. Helping developers learn and share knowledge. Contact me at kbe@voxxed.com with any news, articles or tutorials.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>