I have a rest template.exchange code written as you can see down below.
<code> response = restTemplate.exchange(uri, HttpMethod.POST, entity, String.class);
statusCode = response.getStatusCode();
message = response.getBody();
</code>
<code> response = restTemplate.exchange(uri, HttpMethod.POST, entity, String.class);
statusCode = response.getStatusCode();
message = response.getBody();
</code>
response = restTemplate.exchange(uri, HttpMethod.POST, entity, String.class);
statusCode = response.getStatusCode();
message = response.getBody();
The first time I bring the server up and hit it, the response comes very quickly within 2.1 seconds. The next time I hit it though, it is taking 30 mins or more.
I have used synchronized block to see if any thread is blocking it
<code>static final String x = ""; // outside the fn within the class
synchronized(x){
response = restTemplate.exchange(uri, HttpMethod.POST, entity, String.class);
statusCode = response.getStatusCode();
message = response.getBody();
}
</code>
<code>static final String x = ""; // outside the fn within the class
synchronized(x){
response = restTemplate.exchange(uri, HttpMethod.POST, entity, String.class);
statusCode = response.getStatusCode();
message = response.getBody();
}
</code>
static final String x = ""; // outside the fn within the class
synchronized(x){
response = restTemplate.exchange(uri, HttpMethod.POST, entity, String.class);
statusCode = response.getStatusCode();
message = response.getBody();
}
The debugger still comes to the restTemplate.exchange() line but after that, it is taking too long.
I tried using postman to check the API and it returns the data quickly everytime.
What am I missing here?
Thanks in advance.
I have used synchronized block to see if any thread is blocking it but it isn’t.