37

I am running the Tomcat that gets delivered with your Eclipse download (no, I don't want to download and install the entire Tomcat), and sometimes it hangs when stopping or restarting, and the only way I can find to make it work is restarting all my Eclipse. I am using it under Windows.

Is there any way to kill the Tomcat process (which doesn't appear in the Task Manager)?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Char
  • 925
  • 2
  • 10
  • 24

5 Answers5

52

It appears as javaw.exe in task manager. An alternative is to execute Tomcat/bin/shutdown.bat.

As to the hang problem, are you sure that your webapp isn't spawning unmanaged threads which might be blocking Tomcat's shutdown?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • no, i had'nt check if my webapp is spawning unmanaged threads. thank you. – Char Dec 03 '10 at 00:47
  • how do i check if my webapp isn't spawning unmanaged threads which might be blocking Tomcat's shutdown ? – Suresh Aug 17 '18 at 10:35
25

On Windows, if you know the port Tomcat listens to (below, it is 8080), you can find the PID of the Tomcat process and then kill it from cmd:

> netstat -aon | find "8080"
  TCP    0.0.0.0:8080           0.0.0.0:0              LISTENING       2196
  TCP    [::]:8080              [::]:0                 LISTENING       2196
> taskkill /pid 2196 /f
  SUCCESS: The process with PID 2196 has been terminated.
Andrei Epure
  • 1,746
  • 1
  • 21
  • 30
10

I use better way to shutdown tomcat when it is not found in task manager.

1) Download TCPView(only 285kb) from following link.

http://technet.microsoft.com/en-in/sysinternals/bb897437.aspx

2) Extract folder and start TCPView application.

3) Right click on java.exe and select End Process option.

this would stop your tomcat easily.. This tool is very useful in monitoring port usage.

NOTE: Running TOMCATPATH/bin/shutdown.bat may not shutdown Tomcat when it contains some demon or unmanaged threads. In such cases TCPView works fine without any issues.

shivadarshan
  • 896
  • 2
  • 15
  • 25
  • Downloading additional Software should always be the very last resort. However, this answer contains the vital information that the shutdown.bat may not shutdown Tomcat properly. – doABarrelRoll721 Dec 02 '15 at 11:43
  • @doABarrelRoll721 thank you, ya i do accept it in case of production environment, but installing it in local system doesn't have considerable impact. Also i hope this method is simple and better way to solve. – shivadarshan Dec 02 '15 at 12:05
3

You can set a timeout on startup and shutdown for your Tomcat server in Eclipse. If these timeouts are exceeded, Eclipse will pop up a message asking you if you want to kill it, or keep waiting.

To set these, double-click the name of the server in your Servers tab. It'll open a window like this:

Eclipse Tomcat settings

There's a Timeouts section on the right hand side. I set startup to a day (so I can debug startup without it timing out), and shutdown to 30 seconds to be generous (usually this can be very short, since most apps can survive a forced shutdown with no issues).

squaregoldfish
  • 709
  • 8
  • 20
  • Of course, if your app is spawning unmanaged threads, which seems to have been the OP's issue, that's something to be detected and cleaned up anyway. The above is just a neat way to have Eclipse time out to prevent you having to wait for eternity. – squaregoldfish Feb 14 '19 at 13:16
1

If you use Linux, try the following steps.

  1. List Tomcat processes (e.g., ps aux | grep catalina)
  2. Locate the strings that look like this: myname 2244 5.5 0.3 57020937 2110741 ? Sl Oct03 5160:01 /usr/lib/jvm/java-1.8.0-<...>/bin/java <...> org.apache.catalina.startup.Bootstrap start
  3. Copy-paste everything between /usr/lib/jvm/<...> and <...>.Bootstrap
  4. Add stop at the end of your command and run it

Essentially, you would take the very same command that was used by Eclipse to start Tomcat and modify the last argument to stop Tomcat.

Alexander Pozdneev
  • 1,289
  • 1
  • 13
  • 31