Home » Archives for Tomasz Nurkiewicz » Page 2

Author Archives: Tomasz Nurkiewicz

Java EE developer, Scala enthusiast. Enjoying data analysis and visualization. Strongly believes in the power of testing and automation.

1.x to 2.x migration: Observable vs. Observable: RxJava FAQ

The title is not a mistake. rx.Observable from RxJava 1.x is a completely different beast than io.reactivex.Observable from 2.x. Blindly upgrading rxdependency and renaming all imports in your project will compile (with minor changes) but does not guarantee the same behavior. In the very early days of the project Observable in 1.x had no notion of backpressure but later on backpressure was included. What does it actually ...

Read More »

flatMap() and the order of events – RxJava FAQ

As we already discovered, flatMap() does not preserve the order of original stream. Let’s illustrate this using the GeoNames API example from previous article: public interface GeoNames { Flowable<Long> populationOf(String city); } By requesting population of multiple cities using flatMap() we have no guarantee that they will arrive in order: Flowable<String> cities = Flowable.just("Warsaw", "Paris", "London", "Madrid"); cities .flatMap(geoNames::populationOf) .subscribe(response -> log.info("Population: {}", response)); The output is ...

Read More »

flatMap() vs. concatMap() vs. concatMapEager() – RxJava FAQ

java-interview-questions-answers

There are three, seamlessly similar operators in RxJava 2.x: flatMap(), concatMap() and concatMapEager(). All of them accept the same argument – a function from original stream’s individual item to a (sub-)stream of arbitrary type. In other words if you have a Flowable<T> you provide a function from T to Flowable<R> for arbitrary R type. After applying any of these operators you end up with Flowable<R>. So how are they different? Sample project First ...

Read More »

Eager subscription – RxJava FAQ

java-interview-questions-answers

While teaching and mentoring RxJava, as well as after authoring a book, I noticed some areas are especially problematic. I decided to publish a bunch of short tips that address most common pitfalls. This is the first part. Observables and Flowables are lazy by nature. This means no matter how heavy or long-running logic you place inside your Flowable, it will get evaluated ...

Read More »

Beware of slow transaction callbacks in Spring

spring-interview-questions-answers

TL;DR If your application is failing to obtain new database connection, restarting ActiveMQ broker may help. Interested? The problem with performance Few months ago we experienced a production outage. Many requests were failing with all too familiar: java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30003ms. at com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:555) ~[HikariCP-2.4.7.jar:na] at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:188) ~[HikariCP-2.4.7.jar:na] at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:147) ~[HikariCP-2.4.7.jar:na] at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:99) ...

Read More »

Small scale stream processing kata. Part 2: RxJava 1.x/2.x

In part 1: thread pools we designed and implemented relatively simple system for processing events in real time. Make sure you read previous part as it contains some classes that we’ll reuse. Just in case here are the requirements: A system delivers around one thousand events per second. Each Event has at least two attributes: clientId – we expect up ...

Read More »

Small scale stream processing kata. Part 1: thread pools

Once again I prepared a programming contest on GeeCON 2016 for my company. This time the assignment required designing and optionally implementing a system given the following requirements: A system delivers around one thousand events per second. Each Event has at least two attributes: clientId – we expect up to few events per second for one client UUID – globally ...

Read More »

Guide to time and date in Java

Properly handling dates, time, time zones, daylight saving time, leap years and such has been my pet peeve for a long time. This article is not a comprehensive guide to time domain, see Date and time in Java – much more detailed but slightly, ekhem, dated. It’s still relevant, but doesn’t cover java.time from Java 8. I want to cover ...

Read More »

Functor and monad examples in plain Java

This article was initially an appendix in our Reactive Programming with RxJava book. However introduction to monads, albeit very much related to reactive programming, didn’t suit very well. So I decided to take it out and publish separately as a blog post. I am aware that “my very own, half correct and half complete explanation of monads” is the new ...

Read More »