r/java • • Nov 15 '21

[Loom] JEP draft: Virtual Threads (Preview)

https://openjdk.java.net/jeps/8277131
175 Upvotes

55 comments sorted by

View all comments

39

u/[deleted] Nov 16 '21

[removed] — view removed comment

11

u/lechnito Nov 16 '21 edited Nov 16 '21

Do you mind sharing what you don't like about the current state of reactive programming in java?

I too have clawed my way up the reactive java learning curve, which for me was particularly steep because I came from a strictly imperative background. But now that I have a few projects under my belt in Reactor, there are aspects of it that I definitely prefer.

For your projects, do you think you would you be able to hit the ground running once Loom becomes generally available or would you wait for some framework that utilizes the new virtual threading model?

6

u/pronuntiator Nov 16 '21

I've never used reactive Java, but from using rxjs in Angular I can only imagine the mind twists you have to do to perform simple joins and maps. Also, how pervasive is it? Do Mono and Flux bubble all the way from a foreign API call through your business code up to your controller?

8

u/[deleted] Nov 16 '21

Yep. It's like async/await. You color your code.

5

u/lechnito Nov 16 '21

Ha! It's true that implementing simple things can be tricky in reactor. There are composition patterns that help but it feels more of an art than science sometimes.

Do Mono and Flux bubble all the way from a foreign API call through your business code up to your controller?

Yes and no...

Yes because with spring webflux for example on some level your application is a chain of reactive operations that gets a subscriber when a request arrives. It doesn't matter how many levels of async operations are below the subscriber, webflux calls your application code reactively.

No because you definitely want to hide reactive constructs like Mono and Flux from core business logic where ever possible. If I needed to call a remote API, I would use spring webflux's WebClient and pass the results into map() if I needed to do something imperative or flatMap() if async.