You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Paolo Gambetti <ga...@gmail.com> on 2009/04/20 09:29:01 UTC

Tomcat doesn't stop if a java thread is running

I have this problem. If in my web application running in Tomcat there is a
java thread running when i stop Tomcat with shutdown.bat or shutdown.sh
tomcat process doesn't end and i have to kill it manually. How can i solve
this problem? Is there anything to change in java threads code?
thank you.

Re: Tomcat doesn't stop if a java thread is running

Posted by Leon Rosenberg <ro...@googlemail.com>.
On Mon, Apr 20, 2009 at 9:29 AM, Paolo Gambetti
<ga...@gmail.com> wrote:
> I have this problem. If in my web application running in Tomcat there is a
> java thread running when i stop Tomcat with shutdown.bat or shutdown.sh
> tomcat process doesn't end and i have to kill it manually. How can i solve
> this problem? Is there anything to change in java threads code?
> thank you.
>

Make this thread a daemon (setDaemon(true)) in constructor.
This will tell the VM that its ok to exit without waiting for this thread.
If you want to give the Thread the possibility to finish some job
before shutting down, don't make it daemon, but register a
ShutdownHook instead.
Also, in the latter case, check for Executor patterns in java 1.5

regards
Leon

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


Re: Tomcat doesn't stop if a java thread is running

Posted by Markus Schönhaber <to...@list-post.mks-mail.de>.
Paolo Gambetti:

> I have this problem. If in my web application running in Tomcat there is a
> java thread running when i stop Tomcat with shutdown.bat or shutdown.sh
> tomcat process doesn't end and i have to kill it manually. How can i solve
> this problem? Is there anything to change in java threads code?
> thank you.

The JVM won't terminate until all non-daemon threads have ended. If your
webapp starts such a thread it has the responsibility to stop it when
needed. You can use a ServletContextListener to do this.

Regards
  mks

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