Question

I am working with Async Http Client in Java with this example . I just want to know about the performance issues when we are calling multiple services at a time asynchronously . I am concerned about the number of CPU cores and the number of threads used in this example. I want to know more about this like :

  1. Is this example uses multiple threads for each request.
  2. If suppose I am making n number of calls at that time CPU cores will not support this to run , how I come to know how many threads it will support based in CPU ?
  3. Is this example is Thread Safe.
Was it helpful?

Solution

Is this example uses multiple threads for each request.

No, it does not

how many threads it will support based in CPU

By default the underlying I/O reactor starts one I/O dispatch thread per CPU core

Is this example is Thread Safe

This question is just too vague. Exactly what class instances are you talking about?

Thread-safety rules that apply to both blocking HttpClient and non-blocking HttpAsyncClient are

  • clients are thread-safe
  • connection managers are thread-safe
  • request / response messages are not thread safe
  • contexts are not thread safe

As far as HttpAsyncClient is concerned, as long as you do not use additional threads to process / generate content, HttpAsyncClient ensures proper access synchronization of all components involved.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top