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?

24

u/[deleted] Nov 16 '21

[removed] — view removed comment

7

u/lechnito Nov 16 '21

Fair points all around!

I think Reactor is hard for beginners and for really anyone who has a traditional java background. The more experience you have with async concepts & functional programming languages, the easier go you will have.

Readable & maintainable unit tests remains challenging. StepVerifier only became readable after I started using the junit5 @ParameterizedTest stuff and writing custom test interfaces with functional helper methods. Honestly, I have started replacing most of the unit tests that involve reactive features with WebTestClient based integration tests just to make life easier.

Getting SLF4J's MDC to work for a homegrown distributed tracing service in Reactor has been a huge issue too. Sometimes I worry that the performance cost of using Hooks & contextWrite() offsets any gains from Reactor.

I'm still wrapping my head around Loom, but I think my initial take is that I would miss some of compositional improvement that accompany reactive streaming. Like operating over streams of T instead of imperative loops for instance.

4

u/MR_GABARISE Nov 16 '21

I'd wager that a proper MDC in Loom would certainly aim to make use of Scope Locals, and it's not even guaranteed that they will ship together.

1

u/Dokiace Nov 16 '21

how did you propagate MDC to reactor project?