# Elastic search transport client singleton

**URL:** https://discuss.elastic.co/t/elastic-search-transport-client-singleton/14766
**Category:** Elasticsearch
**Created:** [December 9, 2013, 3:05am UTC](https://discuss.elastic.co/t/elastic-search-transport-client-singleton/14766 "2013-12-09T03:05:13Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![cyrilforce](https://avatars.discourse-cdn.com/v4/letter/c/76d3ee/32.png) [@cyrilforce](https://discuss.elastic.co/u/cyrilforce)
#### Post date: [December 9, 2013, 3:05am UTC](https://discuss.elastic.co/t/elastic-search-transport-client-singleton/14766/1 "2013-12-09T03:05:13Z")

</div>

Hi All,

I had created a transport client singleton that's being used in a web  
application. I would like to know that if i didn't close the transport  
client will it create memory leaks as we do re-deploy the web application  
constantly. In addition, what is the best practices on handling the  
elastic search transport client ? As i wanted the transport client shared  
and reuse by multiple code in the same web application.  
Should i just let the connection timeout itself or explicit close the  
connection for each web deploy.

Thanks.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/f93d9e26-d02c-4320-8887-ad9ae1c4fd20%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f93d9e26-d02c-4320-8887-ad9ae1c4fd20%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)
#### Post date: [December 9, 2013, 8:52am UTC](https://discuss.elastic.co/t/elastic-search-transport-client-singleton/14766/2 "2013-12-09T08:52:48Z")

</div>

The TransportClient uses a thread pool for managing connections to remote  
nodes.

For each web deploy, it is important to close all resources with  
client.close() and to release the threadpool with  
client.threadPool().shutdown()

Example:  
[https://github.com/jprante/elasticsearch-support/blob/master/src/main/java/org/xbib/elasticsearch/support/client/TransportClientBase.java#L90](https://github.com/jprante/elasticsearch-support/blob/master/src/main/java/org/xbib/elasticsearch/support/client/TransportClientBase.java#L90)

You can share a client instance between many concurrent threads. There is  
no need to close transport client connections after actionGet().

Jörg

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAKdsXoH7jYjX7%3D15P%2BaRTgzOAeigwiJsSVRFwbzY1xB5OwOLiw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoH7jYjX7%3D15P%2BaRTgzOAeigwiJsSVRFwbzY1xB5OwOLiw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![cyrilforce](https://avatars.discourse-cdn.com/v4/letter/c/76d3ee/32.png) [@cyrilforce](https://discuss.elastic.co/u/cyrilforce)
#### Post date: [December 10, 2013, 8:20am UTC](https://discuss.elastic.co/t/elastic-search-transport-client-singleton/14766/3 "2013-12-10T08:20:50Z")

</div>

Hi Jörg,

Thanks for you advices.I have implemented the close conn mechanism through  
the servletcontextlistener as it is a webapp.

Thanks.  
Cyril

On Mon, Dec 9, 2013 at 4:52 PM, [joergprante@gmail.com](mailto:joergprante@gmail.com) \<[joergprante@gmail.com](mailto:joergprante@gmail.com)

> wrote:

> The TransportClient uses a thread pool for managing connections to remote  
> nodes.
> 
> For each web deploy, it is important to close all resources with  
> client.close() and to release the threadpool with  
> client.threadPool().shutdown()
> 
> Example:  
> [https://github.com/jprante/elasticsearch-support/blob/master/src/main/java/org/xbib/elasticsearch/support/client/TransportClientBase.java#L90](https://github.com/jprante/elasticsearch-support/blob/master/src/main/java/org/xbib/elasticsearch/support/client/TransportClientBase.java#L90)
> 
> You can share a client instance between many concurrent threads. There is  
> no need to close transport client connections after actionGet().
> 
> Jörg
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/Iz1omfHq0Yc/unsubscribe](https://groups.google.com/d/topic/elasticsearch/Iz1omfHq0Yc/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/CAKdsXoH7jYjX7%3D15P%2BaRTgzOAeigwiJsSVRFwbzY1xB5OwOLiw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoH7jYjX7%3D15P%2BaRTgzOAeigwiJsSVRFwbzY1xB5OwOLiw%40mail.gmail.com)  
> .
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
Regards,

Chee Hoo

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGS0%2Bg9aaFHPtPt3XBuYuwj\_MKLnLNdOX%2BL0iGm1EGRvnQ1XTQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGS0%2Bg9aaFHPtPt3XBuYuwj_MKLnLNdOX%2BL0iGm1EGRvnQ1XTQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:02am UTC](https://discuss.elastic.co/t/elastic-search-transport-client-singleton/14766/4 "2017-07-06T02:02:18Z")

</div>


