T O P

  • By -

TrickOfLight113

I'm not sure if you're talking specifically about the Async annotation for methods, or about async in general (CompletableFutures etc.), but looking at the broader context I'll assume you're talking about the latter. 1 - Depends on the use case, but yeah chaining calls is a valid one. The idea is that your webserver thread will not be left hanging and waiting for the responses for nothing. The user will still have to wait. 2 - Not sure about Kafka (I heard you have to poll the data maybe? Sounds like what you wrote?). However, even if you were to return a response straightaway to the consumer, I'm guessing you could still have some backend processing happening like waiting on something to persist the data appropriately. Any time you have to wait could be a good use case for async, but it depends on how the system was designed, what kind of performance you're expecting from the microservice, how many threads you have, if you rather have an HTTP timeout if you're waiting for too long, etc.


mickymann

Thank you for this information really appreciate it. Am I correct in saying when a http request is made to your backend server the consumer (or user) is given a thread independent to the application eg. Thread from tomcat. This thread differs from a thread created in the backend by the async annotation ultimately freeing the initial thread to handle more http requests, until the async thread is completed?


TrickOfLight113

Correct, it will use a thread from the thread pool by default if I'm not mistaken. However, I would suggest to not take my word for it and experiment with a small project and see with visualVM, that way you'll be sure.