ahww520 / xmemcached

Automatically exported from code.google.com/p/xmemcached
Apache License 2.0
0 stars 0 forks source link

Daemonize threads? #212

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Can't find an option for daemonizing the threads

Original issue reported on code.google.com by dust...@gmail.com on 22 Aug 2012 at 5:42

GoogleCodeExporter commented 8 years ago
I am sorry,what's your meaning?

Original comment by killme2...@gmail.com on 26 Aug 2012 at 7:40

GoogleCodeExporter commented 8 years ago
for example the following:

    public static void main(String ...strings) throws TimeoutException, InterruptedException, MemcachedException, IOException {
         MemcachedClientBuilder builder = new XMemcachedClientBuilder(
                 AddrUtil.getAddresses("localhost:11211"));
         builder.setCommandFactory(new BinaryCommandFactory());//use binary protocol 
         builder.setConnectionPoolSize(5);
         //set the hashing alg.
         builder.setSessionLocator(new KetamaMemcachedSessionLocator());

         MemcachedClient client = builder.build();
         client.get("example");

         System.out.println("DONE, process should exit now, but doesn't");

    }

This program will never exit due to the xmemcached threads not being daemonized.

Original comment by dust...@gmail.com on 27 Aug 2012 at 8:25

GoogleCodeExporter commented 8 years ago
@dustinn

You must call shutdown method to stop the client.

Original comment by killme2...@gmail.com on 28 Aug 2012 at 5:33

GoogleCodeExporter commented 8 years ago
Yes, I know.  Problem is I don't always have control of where to shutdown the 
xmemcached client.  This really needs a daemon option for the threadpool.

found this in WorkerThreadFactory

if (t.isDaemon()) {
t.setDaemon(false);
}

Any way you can make this a config option?

Original comment by dust...@gmail.com on 28 Aug 2012 at 5:33

GoogleCodeExporter commented 8 years ago
Experiencing the same issue where our jobs don't exit after completion with the 
use of xmemcached client.
We don't have access to the client either as it's created by another 
intermediary library.
Setting threads as a daemon won't hurt your functionality. It will just let the 
JVM know that those threads are supporting threads and not main functionality, 
so when the main application threads are done, the JVM can ignore them and 
safely exit.
Many other supporting threads such as "MySQL Statement Cancellation Timer" and 
"Finalizer" are daemons.
Xmemcached-Reactors and xmemcached-read-thread should be as well.
You can register Runtime.addShutdownHook if you'd like to do any custom cleanup 
on JVM exit.
It should be a safe change that we'd welcome!
Thank you for your consideration.

Original comment by cyril.bo...@koinzmedia.com on 2 May 2013 at 5:10

GoogleCodeExporter commented 8 years ago
1.4.2 released.It was fixed.

Original comment by killme2...@gmail.com on 19 Jul 2013 at 6:49