#Async requests

1 messages · Page 1 of 1 (latest)

iron kernelBOT
#

<@&987246399047479336> please have a look, thanks.

long current
#

okhttp is ok?

light pagoda
#

HttpClient built in in Java

#

No need for third party dependencies

long current
#

i fmy project uses spring

light pagoda
#

if you have spring webclient is also fine, but I don't know if you need webflux for that

#

depends on the setup/java version/ virtual threads or not

light pagoda
#

mvc?

long current
#

yeah java 21 spring boot mvc

light pagoda
#

If you’re running on Java 21 or up, you can enable virtual threads by setting the property spring.threads.virtual.enabled to true.

#

And then just use RestTemplate

#

It doesn't block main thread anymore then

long current
light pagoda
#

webflux on java 21 with virtual threads is just a bad idea

#

It overcomplicates things for no reason

long current
#

but do i need to enable them?

light pagoda
#

Is your problem "blocking the main thread", or is it "I want to run multiple requests in parallel"

long current
#

i think in parallel

#

need to be able to enqueu some requests with executor

light pagoda
#

OK

#

XY

#

What is your goal?

long current
#

i have api

light pagoda
#

Yes

long current
#

just wanna be able to make this requests work in parallel

light pagoda
#

ok

#

Do you need the results as well?

long current
#

its kind of assesment

#

for job

#

and requirements are java 21

#

so im trying to think how to do it in most optimal way

light pagoda
#

I'd use Virtual Threads then

long current
#

Its like calling 1 api endpoint filtering it calling another api and thats it i think

#

are they then still a thing?

light pagoda
#

ah it's not in parallel then

#

That's serial

#

call one, results, call other with results of first

long current
#

Yeah i was thinking more like another request coming

#

while the previous one is still being processed

light pagoda
#

ok wtf are you doing, because now you're talking about an api you are implementing

#

And just now it was a client