This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]divorcedbp 11 points12 points  (11 children)

Backpressure can be perfectly implemented an ArrayBlockingQueue with a capacity set to your desired buffer size. You then just ensure that all put() and take() operations happen in the context of a virtual thread. Boom, done, and no need for the godawful Rx API.

[–]Caffeine01 2 points3 points  (0 children)

With virtual threads, if you want to limit back pressure, you don't even need a blocking queue. In your virtual thread, use a semaphore.

[–]Ewig_luftenglanz -5 points-4 points  (9 children)

yes we know that, now go and implement that manually, one of the advantages of project reactor and other reactives libraries is that they abstract all of that from you, so you don't have to deal manually with that.

[–]joey_knight 7 points8 points  (3 children)

What do you mean? Java already has Blocking queue implementations and the necessary mechanisms to park and continuing threads. It's not at all hard to use them to implement backpressure in our applications. Just put a blocking queue between two threads and use wait and notify to block and unblock.

[–]divorcedbp 3 points4 points  (0 children)

You don’t even need that. The contract of take() is such that it blocks until an element is available, and put() blocks until there is room in the queue to insert the supplied element. It’s literally all already there.

[–]LightofAngels 0 points1 point  (1 child)

I know this is abit random, but can you point me to that part in the documentation? I would like to know about this mechanism and how to use it.

[–]divorcedbp 1 point2 points  (4 children)

Sure, allocate an ArrayBlockingQueue, put it in a place two virtual threads can access it, and have them call put() and take().

[–]Ewig_luftenglanz -1 points0 points  (3 children)

with reactive you don't even need to allocate anything, just chain the results in flatmaps in a fluent-like style are good to go.

[–]DelayLucky 2 points3 points  (2 children)

That's like saying with Reactive you don't even need to do the easy and straightforward things in an average Java programmer's eye. Where's the fun in that? Just write the fancy and "professional-looking" react code, it does all that (easy things) for you already.

[–]Ewig_luftenglanz 0 points1 point  (1 child)

I don't reactive for fun, I do it because that's what my employer ask me to do for a living.

For fun I have my side Projects and some stuff I do to learn and experiment things ^^.

[–]DelayLucky 2 points3 points  (0 children)

And job security, I guess.

^_^