-1

I have a threadpool in which threads are calling an api with different bodies. Its a post call. Currently I am mesauring response time like this.

long start = System.currentTimeMillis(); 
restTemplate call. 
long end = System.currentTimeMillis()
responseTime = end - start;

I am assuming when restTemplate call will be made context will get switched by OS and no guarantee when it will be switched back. So how will the correct response time be measured.

1 Answers1

0

If your rest call is synchronous, it does not matter that which thread is handled your request since it will be blocked anyways. But, if you are doing async calls, of course you should calculate finish time in response callback implementation.

Ali Can
  • 564
  • 3
  • 15
  • is there any benefit of using a thread pool to make different rest callls to api. if my call is syncrhonous. Also I am assuming that restTemplate call done in this manner response = restTemplate.postForEntity(url, request, ResponseDTO.class); is a synchronous call. Also is there any performance benefit if I make my call asynchornous vs using a thread pool to make synchronous calls to the rest api. – yatharth govil Feb 14 '21 at 07:10
  • I did not understand why you want to use thread pool in your use case. It's better to use asynchronous api to make **parallel requests**. But, if you refer to [connection pooling](https://en.wikipedia.org/wiki/Connection_pool) then you do not need to worry about the measuring http request duration due to the reason that I wrote in the answer. See [javadoc PoolingHttpClientConnectionManager](https://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.html) – Ali Can Feb 14 '21 at 10:09