-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Carsten,

On 6/17/2009 4:33 AM, CBy wrote:
> O'Reilly's Tomcat The Definitive Guide advises me to invoke the
> setDaemon(true) method on any Thread object a web application creates to
> keep them from hanging the JVM when Tomcat shuts down. My web service,
> however, uses a thread pool that is created via
> java.util.concurrent.Executors.newFixedThreadPool(NTHREADS) and I don't
> know how to make them daemon threads in this case.

Can you adjust that code? If so, use the form of that method that takes
a ThreadFactory object. Something like this ought to do it:

public class DaemonThreadFactory
    implements ThreadFactory
{
   public Thread newThread(Runnable r)
   {
      Thread t = new Thread(r);
      t.setDaemon(true);

      return t;
   }
}

> My new plan was to register a shutdown hook with the JVM in my web
> service and to invoke shutdown() or shutdownNow() on the ExecutorService
> in it (the method above returns an ExecutorService). Unfortunately, this
> does not seem to work.

You should do as André suggests and use a ServletContextListener. You
should probably use the same listener to both create and teardown the
thread pool.

I recently had my first experience with Executors in Java. I have to say
that I love 'em. So simple, yet so powerful.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAko5KyoACgkQ9CaO5/Lv0PDgcQCfVTfVdv3xUXsEFhh+PYWy9uII
hpoAn37qoHfLeSVot+FjaYI3XS+8deeH
=j4WL
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to