# Transport Client

**URL:** <https://discuss.elastic.co/t/transport-client/7126>\
**Category:** Elasticsearch\
**Created:** [March 26, 2012, 12:11pm UTC](https://discuss.elastic.co/t/transport-client/7126 "2012-03-26T12:11:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ElasticUsers](https://avatars.discourse-cdn.com/v4/letter/e/51bf81/32.png) [@ElasticUsers](https://discuss.elastic.co/u/ElasticUsers)\
**Post date:** [March 26, 2012, 12:11pm UTC](https://discuss.elastic.co/t/transport-client/7126/1 "2012-03-26T12:11:22Z")

</div>

Hi Team,

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.

Kindly advice.

Regards

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 26, 2012, 12:30pm UTC](https://discuss.elastic.co/t/transport-client/7126/2 "2012-03-26T12:30:22Z")

</div>

IMHO, it's best to have a singleton factory and close the TransportClient  
only when you shutdown the webapp.

That's what I did in production without issues.

HTH,  
David.

Le 26 mars 2012 à 14:11, ElasticUsers [kranti\_123@rediffmail.com](mailto:kranti_123@rediffmail.com) a écrit :

> Hi Team,
> 
> 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.
> 
> Kindly advice.
> 
> Regards
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Transport-Client-tp3857974p3857974.html](http://elasticsearch-users.115913.n3.nabble.com/Transport-Client-tp3857974p3857974.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--  
David Pilato  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [March 27, 2012, 1:15pm UTC](https://discuss.elastic.co/t/transport-client/7126/3 "2012-03-27T13:15:26Z")

</div>

Yes, keep the TransportClient instance around, and reuse it.

On Mon, Mar 26, 2012 at 2:30 PM, [david@pilato.fr](mailto:david@pilato.fr) [david@pilato.fr](mailto:david@pilato.fr) wrote:

> \*\*
> 
> IMHO, it's best to have a singleton factory and close the TransportClient  
> only when you shutdown the webapp.
> 
> That's what I did in production without issues.
> 
> HTH,
> 
> David.
> 
> Le 26 mars 2012 à 14:11, ElasticUsers [kranti\_123@rediffmail.com](mailto:kranti_123@rediffmail.com) a  
> écrit :
> 
> > Hi Team,
> > 
> > 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.
> > 
> > Kindly advice.
> > 
> > Regards
> > 
> > --  
> > View this message in context:  
> > [http://elasticsearch-users.115913.n3.nabble.com/Transport-Client-tp3857974p3857974.html](http://elasticsearch-users.115913.n3.nabble.com/Transport-Client-tp3857974p3857974.html)  
> > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).
> 
> --  
> David Pilato  
> [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> Twitter : @dadoonet

---

<div class="post-metadata">

**Author:** ![ElasticUsers](https://avatars.discourse-cdn.com/v4/letter/e/51bf81/32.png) [@ElasticUsers](https://discuss.elastic.co/u/ElasticUsers)\
**Post date:** [April 9, 2012, 6:59am UTC](https://discuss.elastic.co/t/transport-client/7126/4 "2012-04-09T06:59:34Z")

</div>

Thanks..

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 3:33am UTC](https://discuss.elastic.co/t/transport-client/7126/5 "2017-07-06T03:33:09Z")

</div>


