We have a Java web application which works in following manner -
1)Obtain TransportClient instance by supplying cluster, url and port.
2)Execute the query using TransportClient instance in step 1 and get the SearchResponse instance.
3)Process the SearchResponce from step 2.
4)Close the TransportClient in finally block of java program by calling TransportClient.close() method.
From the web app whenever user hit the Search button from GUI we perform the above steps for each Search operation.
I have a question - Is it correct to obtain a TransportClient for each search operation and close it after SearchResponse is processed in finally block? But I have read somewhere that since Transport client is thread safe so we should obtain it in a singleton factory and close it only when we shut the server down (in our case the server is Jboss) or when the application is down.