How to use RestTemplate efficiently in Multithreaded environment?

后端 未结 3 1332
耶瑟儿~
耶瑟儿~ 2020-12-08 02:42

I am working on a project in which I need to make a HTTP URL call to my server which is running Restful Service which returns back the response as a JSON String

3条回答
  •  轮回少年
    2020-12-08 03:48

    A RestTemplate is thread safe once constructed, so you can construct one instance and have all your tasks share it. That will be much more efficient, because you eliminate the construction cost from each task, and reduce the load on the garbage collector.

提交回复
热议问题