0

I have a java restful web service implemented, and I have one method in that ws that makes a HTTP request which takes like 3-4 minutes, I want to know if I can get any benefit of making that call asynchronous.

The thread could be used by another request or will be blocked anyway by the main call?

Edit: I am making a petition P to my web service A (a synchronous petition only), that petition is handled by thread T1, when the petition P call the URL that takes 3-4 minutes, would I get benefits if I make that call asynchronous (to the URL that takes 3-4 minutes). Benefits like the thread T1 will be able to handle new petitions?. If the answer is no, then are there another benefit in doing that call asynchronously?

Jose Da Silva Gomes
  • 3,814
  • 3
  • 24
  • 34

1 Answers1

0

It's not good to block a HTTP request for such a long time, because HTTP is synchronous.

Instead of blocking, it would be better to make it asynchronous and return 202 Accepted. For getting the result you got two choices:

  • polling (client periodically polls for a result)
  • callback (notify client with help of callback-url)

For further reading look at this blogpost: https://www.adayinthelifeof.nl/2011/06/02/asynchronous-operations-in-rest/ or Best way to create REST API for long lasting tasks?.

Community
  • 1
  • 1
Theiaz
  • 568
  • 6
  • 24