# ElasticSearch Java Client with Spring doesn't stop

**URL:** <https://discuss.elastic.co/t/elasticsearch-java-client-with-spring-doesnt-stop/8071>\
**Category:** Elasticsearch\
**Created:** [June 13, 2012, 5:53am UTC](https://discuss.elastic.co/t/elasticsearch-java-client-with-spring-doesnt-stop/8071 "2012-06-13T05:53:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eugene\_Strokin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eugene_strokin/32/1238_2.png) [@Eugene\_Strokin](https://discuss.elastic.co/u/Eugene_Strokin)\
**Post date:** [June 13, 2012, 5:53am UTC](https://discuss.elastic.co/t/elasticsearch-java-client-with-spring-doesnt-stop/8071/1 "2012-06-13T05:53:50Z")

</div>

Hello,  
I'm using Spring Bean to initialize ES TransportClient: see the code here:

> <https://gist.github.com/strokine/2922102>

  
I just @Autowire EsClientProvider and everything works fine, except when  
application stops, I still have threads running and it hangs, and I need to  
kill the process to stop it.  
Is anything could be done about this?  
I've also tried explicitly call getClient().stop() before application  
exits, but it doesn't change anything.

Thank you,  
Eugene S.

---

<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:** [June 13, 2012, 6:42am UTC](https://discuss.elastic.co/t/elasticsearch-java-client-with-spring-doesnt-stop/8071/2 "2012-06-13T06:42:07Z")

</div>

Yes. It's a pain.  
It's relative to this issue : [FinalizableReferenceQueue keeps ClassLoaders around. · Issue #92 · google/guava · GitHub](http://code.google.com/p/guava-libraries/issues/detail?id=92)

BTW, may I suggest that you gave a look at the ES Spring Project ? : [GitHub - dadoonet/spring-elasticsearch: Spring factories for elasticsearch](https://github.com/dadoonet/spring-elasticsearch)

Cheers  
David

Le 13 juin 2012 à 07:53, Eugene Strokin [eugene@strokin.info](mailto:eugene@strokin.info) a écrit :

> Hello,  
> I'm using Spring Bean to initialize ES TransportClient: see the code here: [ElasticSearch Client on Spring · GitHub](https://gist.github.com/2922102)  
> I just @Autowire EsClientProvider and everything works fine, except when application stops, I still have threads running and it hangs, and I need to kill the process to stop it.  
> Is anything could be done about this?  
> I've also tried explicitly call getClient().stop() before application exits, but it doesn't change anything.
> 
> Thank you,  
> Eugene S.

---

<div class="post-metadata">

**Author:** ![Eugene\_Strokin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eugene_strokin/32/1238_2.png) [@Eugene\_Strokin](https://discuss.elastic.co/u/Eugene_Strokin)\
**Post date:** [June 13, 2012, 4:12pm UTC](https://discuss.elastic.co/t/elasticsearch-java-client-with-spring-doesnt-stop/8071/3 "2012-06-13T16:12:25Z")

</div>

Thank you David, I'll try spring-elasticsearch out.  
Did you find any solution for this hang up problem? I need to run some jobs  
periodically which are using ES. I was planing to use cron, but with this  
problem, I end up with lots of hanging process. Not acceptable for  
production.

Thanks again  
Eugene

On Wednesday, June 13, 2012 2:42:07 AM UTC-4, David Pilato wrote:

> Yes. It's a pain.  
> It's relative to this issue :  
> [FinalizableReferenceQueue keeps ClassLoaders around. · Issue #92 · google/guava · GitHub](http://code.google.com/p/guava-libraries/issues/detail?id=92)
> 
> BTW, may I suggest that you gave a look at the ES Spring Project ? :  
> [GitHub - dadoonet/spring-elasticsearch: Spring factories for elasticsearch](https://github.com/dadoonet/spring-elasticsearch)
> 
> Cheers  
> David
> 
> Le 13 juin 2012 à 07:53, Eugene Strokin a écrit :
> 
> > Hello,  
> > I'm using Spring Bean to initialize ES TransportClient: see the code  
> > here: [ElasticSearch Client on Spring · GitHub](https://gist.github.com/2922102)  
> > I just @Autowire EsClientProvider and everything works fine, except when  
> > application stops, I still have threads running and it hangs, and I need to  
> > kill the process to stop it.  
> > Is anything could be done about this?  
> > I've also tried explicitly call getClient().stop() before application  
> > exits, but it doesn't change anything.
> > 
> > Thank you,  
> > Eugene S.

---

<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:** [June 13, 2012, 8:09pm UTC](https://discuss.elastic.co/t/elasticsearch-java-client-with-spring-doesnt-stop/8071/4 "2012-06-13T20:09:14Z")

</div>

No. I did not try to find a solution as Google said at first that the issue was  
closed. Shay gets in the 0.19 branch the last version of Guava. But then the  
issue was reopened... ☹  
I'm not sure that there is a solution actually...

Also, in production, by now, each time I push a new version of my project, Sysop  
team restart my jboss instance. So I don't really have Threads remaining.

But it's really a pain when you want to debug under tomcat as each time tomcat  
restart, I get OOM exceptions...

You said that you run jobs using cron. That means that you start each time a new  
jvm and stop it after the end of the job ?  
If so, it should not be a problem for you as you kill the java process...

David

Le 13 juin 2012 à 18:12, Eugene Strokin [eugene@strokin.info](mailto:eugene@strokin.info) a écrit :

> Thank you David, I'll try spring-elasticsearch out.  
> Did you find any solution for this hang up problem? I need to run some jobs  
> periodically which are using ES. I was planing to use cron, but with this  
> problem, I end up with lots of hanging process. Not acceptable for production.
> 
> Thanks again  
> Eugene
> 
> On Wednesday, June 13, 2012 2:42:07 AM UTC-4, David Pilato wrote:
> 
> > > Yes. It's a pain.  
> > > It's relative to this issue :  
> > > [FinalizableReferenceQueue keeps ClassLoaders around. · Issue #92 · google/guava · GitHub](http://code.google.com/p/guava-libraries/issues/detail?id=92)
> > 
> > BTW, may I suggest that you gave a look at the ES Spring Project ? :  
> > [http://code.google.com/p/guava-libraries/issues/detail?id=92](http://code.google.com/p/guava-libraries/issues/detail?id=92)  
> > [GitHub - dadoonet/spring-elasticsearch: Spring factories for elasticsearch](https://github.com/dadoonet/spring-elasticsearch)
> > 
> > Cheers  
> > David
> > 
> > Le 13 juin 2012 à 07:53, Eugene Strokin a écrit :
> > 
> > > Hello,  
> > > I'm using Spring Bean to initialize ES TransportClient: see the code  
> > > here: [https://github.com/dadoonet/spring-elasticsearch](https://github.com/dadoonet/spring-elasticsearch)  
> > > [ElasticSearch Client on Spring · GitHub](https://gist.github.com/2922102)  
> > > I just @Autowire EsClientProvider and everything works fine, except  
> > > when application stops, I still have threads running and it hangs, and  
> > > I need to kill the process to stop it.  
> > > Is anything could be done about this?  
> > > I've also tried explicitly call getClient().stop() before application  
> > > exits, but it doesn't change anything.
> > > 
> > > Thank you,  
> > > Eugene S.  
> > > [https://gist.github.com/2922102](https://gist.github.com/2922102)
> 
> [https://gist.github.com/2922102](https://gist.github.com/2922102)

--  
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:** [June 14, 2012, 9:46pm UTC](https://discuss.elastic.co/t/elasticsearch-java-client-with-spring-doesnt-stop/8071/5 "2012-06-14T21:46:57Z")

</div>

Which threads are still running? Are those the ones listed on the top of  
the gist? if so, they are not ES related.

On Wed, Jun 13, 2012 at 7:53 AM, Eugene Strokin [eugene@strokin.info](mailto:eugene@strokin.info) wrote:

> Hello,  
> I'm using Spring Bean to initialize ES TransportClient: see the code here:  
> [ElasticSearch Client on Spring · GitHub](https://gist.github.com/2922102)  
> I just @Autowire EsClientProvider and everything works fine, except when  
> application stops, I still have threads running and it hangs, and I need to  
> kill the process to stop it.  
> Is anything could be done about this?  
> I've also tried explicitly call getClient().stop() before application  
> exits, but it doesn't change anything.
> 
> Thank you,  
> Eugene S.

---

<div class="post-metadata">

**Author:** ![Eugene\_Strokin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eugene_strokin/32/1238_2.png) [@Eugene\_Strokin](https://discuss.elastic.co/u/Eugene_Strokin)\
**Post date:** [June 14, 2012, 10:08pm UTC](https://discuss.elastic.co/t/elasticsearch-java-client-with-spring-doesnt-stop/8071/6 "2012-06-14T22:08:11Z")

</div>

Sorry, I should've included more details about the threads.  
I've updated the Gist:

> <https://gist.github.com/strokine/2922102>

The top one are the threads which are still running after application exits.  
Thank you  
Eugene

On Thursday, June 14, 2012 5:46:57 PM UTC-4, kimchy wrote:

> Which threads are still running? Are those the ones listed on the top of  
> the gist? if so, they are not ES related.
> 
> On Wed, Jun 13, 2012 at 7:53 AM, Eugene Strokin wrote:
> 
> > Hello,  
> > I'm using Spring Bean to initialize ES TransportClient: see the code  
> > here: [ElasticSearch Client on Spring · GitHub](https://gist.github.com/2922102)  
> > I just @Autowire EsClientProvider and everything works fine, except when  
> > application stops, I still have threads running and it hangs, and I need to  
> > kill the process to stop it.  
> > Is anything could be done about this?  
> > I've also tried explicitly call getClient().stop() before application  
> > exits, but it doesn't change anything.
> > 
> > Thank you,  
> > Eugene S.

---

<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:24am UTC](https://discuss.elastic.co/t/elasticsearch-java-client-with-spring-doesnt-stop/8071/7 "2017-07-06T03:24:03Z")

</div>


