xieguoking / hibernate-memcached

Automatically exported from code.google.com/p/hibernate-memcached
0 stars 0 forks source link

hibernate-memcached used in web application starts thread that doesn't stop #19

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
As the summary states i am using hibernate-memcached in my web application 
which runs on tomcat. As soon as i active the cache it is not possible to stop 
tomcat the normal way but i have to kill it. I tracked the problem an i am 
quite sure that this comes from a thread that is started for the communication 
with the memcached server. This thread doesn't get stopped anymore and so 
tomcat cannot be stopped as well.

I am not sure which class the thread is of and if this is your fault or the 
fault of spymemcached client but could you please give me some feedback on this 
problem.

Thanks a lot!

Original issue reported on code.google.com by Werzi2...@gmx.de on 7 Aug 2010 at 1:15

GoogleCodeExporter commented 9 years ago
Try using hibernate-memcached with the latest version of spymemcached.

If that doesn't help and you think there's a bug, I suggest the following...
Dive into the source code and find a fix. 
Fork the project and provide a patch.
Send a pull request and I'll merge it in.

Original comment by raykrue...@gmail.com on 7 Aug 2010 at 1:18

GoogleCodeExporter commented 9 years ago
I already updated to the current version of spymemcached (2.5) but the problem 
still exists.

Where do you think the bug is... hibernate-memcached or spymemcached (so which 
source to have a look at)?

But i have to admit that i am not the guru java coder... so the outcome from a 
patch of mine i unsure ;)

Original comment by Werzi2...@gmx.de on 7 Aug 2010 at 1:26

GoogleCodeExporter commented 9 years ago
After a long time i digged into this problem again. I asked the spymemcached 
and they told me that the shutdown() method must be called to terminate the 
threads.

As i looked at your code you seem to call this method from
com.googlecode.hibernate.memcached.spymemcached.SpyMemcache.shutdown()

But this method itself never gets called. Is this a bug in 
hibernate-memcached... this method should get called, shouldn't it? Or is there 
any way i can call this method on my on on application shutdown (i don't see 
that hibernate has any API to get this done).

Thanks!

Original comment by we...@appsoft.de on 1 Mar 2011 at 3:31

GoogleCodeExporter commented 9 years ago
Hibernate creates many instances of the cache implementation we provide to it. 
All of those instances share the same spymemcached client. Which means that 
when hibernate tells us to destroy the cache, we cannot safely shutdown the 
client...
https://github.com/raykrueger/hibernate-memcached/blob/master/src/main/java/com/
googlecode/hibernate/memcached/MemcachedCache.java#L192

If you look at the code that creates the Spymecache client...
https://github.com/raykrueger/hibernate-memcached/blob/master/src/main/java/com/
googlecode/hibernate/memcached/spymemcached/SpyMemcacheClientFactory.java

You'll see that there is a property there for enabling daemon mode via a config 
property.
Set hibernate.memcached.daemonMode=true and you should be good.

This tells spymemcache to use daemon threads that shutdown with the VM.

In the future please use the google group for questions and the issue tracking 
for actual confirmed bugs.

Original comment by raykrue...@gmail.com on 1 Mar 2011 at 3:41

GoogleCodeExporter commented 9 years ago
That the client is not shut on destroying a cache seems to be ok but there 
should be a point when the client is shut down (at least there should be a 
possibility to do this on my own).

No setting daemonMode doesn't fix the problem. Tomcat cannot shutdown as some 
threads seems to remain running.

Could you please tell me where to find the google group? Although i consider 
this as a bug.

Original comment by we...@appsoft.de on 1 Mar 2011 at 3:57

GoogleCodeExporter commented 9 years ago
I found the group :)
http://groups.google.com/group/hibernate-memcached?pli=1

Original comment by we...@appsoft.de on 1 Mar 2011 at 3:58