Hi,

>Questions:
>  1. Is Tomcat's behavior on this point user-configurable (and if so
>  how)?
>  2. If it's not, I'd appreciate any pointers to information about
>  exactly how Tomcat handles this.
>
>[...On re-reading this passage from the servlets spec, I realize that
>"any threads that are currently running in the service method" is murky
to
>me. Is this supposed to be more restrictive than "any threads that have
>ever been started by the servlet instance (including during init()) and
>that are still running"?]

Yes, it's supposed to be much more restrictive.  Any threads in the
service() methods means exactly that, and nothing more.  If you start
any threads during init(), destroy(), or wherever (including service())
for that matter, you are responsible for their shutdown on system
shutdown.  Typically the simplest way to avoid problems here is to mark
these threads as daemons.  There are other solutions should you need
them.

The JVM will not exit if there are any user non-daemon threads running.
The JavaDoc for the java.lang.Thread class is pretty clear on this
point.  You have to have an explicit System.exit() call in your code to
handle that case, which of course is hazardous in other ways.
Alternatively, have some sort of a singleton start all your threads and
on shutdown let the singleton know to stop/kill them all.  One possible
place to do this (that's much better for this purpose than a servlet's
destroy() method is a ServletContextListener's contextDestroyed() event.

Tomcat handles this in a strictly standards-compliant (which is not to
say ideal, but which I actually like) way.  Tomcat will exit, i.e. stop
listening on that port and stop its own threads, properly.  However, the
JVM itself will keep running.  You will not be able to start another
tomcat on the same port (you'll get a BindException, Address Already In
Use).  So this is one situation you want to avoid.

Yoav Shapira
Millennium ChemInformatics

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to