Concurrency made easy with Kotlin Coroutines

by | Feb 12, 2022 | Voxxed Days Bucharest 2022

Riccardo Lippolis is an inquiring and experienced Java/Kotlin Developer with a passion for solving complex problems. Known by his colleagues as the Kotlin Hipster (probably because of the beard), he is the go-to guy for everything Kotlin-related. He works for JDriven, where he shares his passion and drive with other enthusiasts.

Riccardo has spoken at several conferences, including (but not limited to): JFall (2016, rated #1), DevoxxUK (2017 & 2021), JavaLand (2017), Code and Comedy (2017, keynote speaker), NextBuild (2017), Spring I/O (2018), GeeCON Kraków (2019), and JavaZone (2021).

Have you ever tried to create a multithreaded application capable of handling all your user requests at the same time, but ended up juggling threads and thread pools, ultimately wondering whether it was worth it in the end? Writing asynchronous or concurrent code has always been notoriously hard. It is difficult to reason about the execution of the code, and requires a lot of boilerplate. Luckily, there is an easier way! Coroutines provide a more intuitive way of writing code that can perform several tasks at once, without much of the usual hassle of dealing with blocking threads and thread pools.

In this talk, I will introduce you to Kotlin Coroutines, a library for writing asynchronous code, developed by JetBrains. The concept of suspending functions is explained, and you will get a firm grasp of what you can do with Kotlin Coroutines and why you should use them, but more importantly how to use them the way they are intended. You will also learn why it is possible to run thousands of coroutines simultaneously, without creating as many threads!

Furthermore, the concept of non-blocking I/O will be explained by creating a fully reactive web application implemented using Spring WebFlux and R2DBC (reactive JDBC), where Kotlin Coroutines are used as the ‘glue’ between the incoming HTTP requests and the calls to the database, with as little boilerplate code as possible.