12

I am planning to use Java REST client in our application. Ours is a Java RESTful application running on Tomcat. We will have lot of search requests to ElasticSearch per second from different users. What is the best practice - To create a Singleton and use it application wide or create one instance per user?

If Singleton is the way to go, how many concurrent requests it can serve? Will that approach be scalable?

Thanks and Regards, Rajesh

fmdaboville
  • 1,394
  • 3
  • 15
  • 28
Rajesh Kumar
  • 273
  • 2
  • 7

1 Answers1

16

Both RestClient and RestHighLevelClient are thread safe. As per documentation you should have only one object per application.

https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/_changing_the_client_8217_s_initialization_code.html

mkalsi
  • 355
  • 1
  • 3
  • 14
  • what if I make multiple new RestHighLevelClient(restClientBuilder); Will that not give multiple Objects? if YES, then should I declare the rest high-level client as static? if NO, then why won't it give multiple Object even after making multiple new Calls – AshishUpadhyay Dec 09 '21 at 14:51