# When a Java process with ES Client terminate, does it automatically close the connection?

**URL:** <https://discuss.elastic.co/t/when-a-java-process-with-es-client-terminate-does-it-automatically-close-the-connection/16003>\
**Category:** Elasticsearch\
**Created:** [February 25, 2014, 9:07am UTC](https://discuss.elastic.co/t/when-a-java-process-with-es-client-terminate-does-it-automatically-close-the-connection/16003 "2014-02-25T09:07:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arinto\_Murdopo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/arinto_murdopo/32/1779_2.png) [@Arinto\_Murdopo](https://discuss.elastic.co/u/Arinto_Murdopo)\
**Post date:** [February 25, 2014, 9:07am UTC](https://discuss.elastic.co/t/when-a-java-process-with-es-client-terminate-does-it-automatically-close-the-connection/16003/1 "2014-02-25T09:07:12Z")

</div>

Hi all,

A question on Java API for ElasticSearch. When a Java process with ES  
Client terminate, does it automatically close the connection? Or we should  
explicitly close the connection to save the resources?

Best regards,

Arinto

--  
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/27516684-8413-4e2c-9c44-021baf85b952%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/27516684-8413-4e2c-9c44-021baf85b952%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:** [February 25, 2014, 9:41am UTC](https://discuss.elastic.co/t/when-a-java-process-with-es-client-terminate-does-it-automatically-close-the-connection/16003/2 "2014-02-25T09:41:58Z")

</div>

Yes, you should always call close() in your code if you want to exit.

There is no automatic call to client close() when a JVM exits.

If the JVM exits, connections will be aborted and throw errors, mostly you  
can see them in the cluster logs (IOExceptions, "connection reset by peer",  
or timeouts).

If the client is closed with close(), the resources the client holds are  
released back to the JVM (connections/sockets, thread pool, caches). ES  
waits for threads to complete if they are active. Also in this case, open  
connections will be forcefully closed, even if operations (executed by  
other threads using the client) are still ongoing, but the message will be  
different, the cluster can react gracefully.

Jörg

On Tue, Feb 25, 2014 at 10:07 AM, Arinto Murdopo [arinto@gmail.com](mailto:arinto@gmail.com) wrote:

> Hi all,
> 
> A question on Java API for Elasticsearch. When a Java process with ES  
> Client terminate, does it automatically close the connection? Or we should  
> explicitly close the connection to save the resources?
> 
> Best regards,
> 
> Arinto
> 
> --  
> 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/27516684-8413-4e2c-9c44-021baf85b952%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/27516684-8413-4e2c-9c44-021baf85b952%40googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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/CAKdsXoFPv%2BU0ACptRcgUs9%3D%2BAx%2B0Ayox\_923dpHYMHS0bwzAVQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoFPv%2BU0ACptRcgUs9%3D%2BAx%2B0Ayox_923dpHYMHS0bwzAVQ%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, 1:47am UTC](https://discuss.elastic.co/t/when-a-java-process-with-es-client-terminate-does-it-automatically-close-the-connection/16003/3 "2017-07-06T01:47:33Z")

</div>


