Sitemap
Javarevisited

A humble place to learn Java and Programming better.

Member-only story

Reactive Database Access with R2DBC, Micronaut and GraalVM

--

Photo by on

In this story I show how to access relational databases from Java in a reactive way using R2DBC. I will therefore create an example project containing a simple rest interface to create, read, update and deleted rows in a PostgreSQL database. The example project will use the Framework running as a native image. As I hope that this combination drastically improves the startup time and memory footprint I will compare those to a similar spring application using MVC and Spring Data.

Reactive Programming

In a traditional Java application, a thread handles one request at a time. At application startup, the application creates a pool with a fixed number of threads. When a request reaches the application, it will take a thread from this pool and assign it to the request. This thread will then compute and send the response and when finished puts itself back into the thread pool. When the application needs to wait for some resources (like a database query, a files system access or the response of an http request) the corresponding thread will be blocked until the resource is available (called “blocking I/O”). As there are many threads, the CPU can in the meantime work on another request managed by another thread.

Javarevisited
Javarevisited

Published in Javarevisited

A humble place to learn Java and Programming better.

Matthias Graf
Matthias Graf

Written by Matthias Graf

Software Architect from Switzerland. Interested in Java, Microservices, Access Management and other

Responses (2)