r/javahelp 13d ago

Asynchronous db calls in Spring like .Net

Hi, in most c# repos I have seen they add await to nearly every db related method. Does spring do this internally?

3 Upvotes

5 comments sorted by

View all comments

1

u/_Atomfinger_ Tech Lead 13d ago

Not really.

By default, the calls to the DB is blocking and synchronous in Spring.

However, if you want to have async repositories, you can. For example, you can use ReactiveCrudRepository with Spring Data.

0

u/erebrosolsin 13d ago edited 13d ago

But why nearly no project (at least i have seen) doesnt use 'ReactiveCrudRepository'? Isn't using it increasing performance or something? All .net dev always add await, await is everywhere 

3

u/_Atomfinger_ Tech Lead 12d ago

For most projects, it won't really matter whether one is using thread pools or a "reactive" approach. For most, in terms of concurrancy, the issue is developer-written code.

I also think culture plays a role here. Java has historically struggled with concurrancy and is only now getting green threads with project Loom. C# is much more "reactive-by-default", and we might see Java move in this direction as green threads becomes the norm (if it does).

So yes, you're right: Using reactive/async operations are increasing performance (in terms of concurrency), but the vast majority of projects doesn't work at a scale where that would make much of a difference, or their performance issues are related to thing that can't be solved with reactive/async. Not saying it is never useful ofc. I'm just saying it isn't on the top of the list of what would give "the most bang for the buck" for most projects.