In Spring Boot,for making a Rest Client call currently creating RestTemplate using the new keyword in multiple classes.
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> response = restTemplate.exchange(
Planning to create a single class that returns a same instance of RestTemplate, and using it for all the Rest calls.
Will it affect performance. What may be the drawbacks on performance or any other?
Also instead of creating a single RestTemplate, is using Pooling a better option? Thanks
Creating a new RestTemplate every time you need to use it will be more expensive then just creating it once and using dependency injection to get a reference to it.
Creating a connection pool would provide an additional performance boost because it would allow connections to be re-used (if that is what you need)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With