Tomcat not shutting down within Eclipse
I'm building a relatively simple web-app where the main servlet implements the ServletContextListener
interface to determine whether the context has been started or stopped. I've implemented my contextInitialized
, contextDestroyed
, init
and destroy
methods (both init
and destroy
call super
on the base class). I've currently implemented no real functionality other than that I've initialized log4j in the contextInitialized
method where I load the log4j.properties
file.
When I start and stop the Tomcat server from within Eclipse however, everything is called in the correct order (I'm using some System.out.println
's to test this) but after about 10 seconds of stopping the server I'm presented with an Eclipse popup stating the following:
Server Tomcat v6.0 Server at localhost is not responding. Do you want to terminate this server? Click 开发者_如何学GoOK to terminate the server or click Cancel to continue waiting.
This is what's printed in my Eclipse console when I stop the server:
04/01/2010 7:39:13 PM org.apache.catalina.core.StandardService stop
INFO: Stopping service Catalina contextDestroyed 04/01/2010 7:39:13 PM org.apache.coyote.http11.Http11Protocol destroy INFO: Stopping Coyote HTTP/1.1 on http-8080
And after the last INFO
message it just hangs there until the popup appears. If I choose to wait, press Cancel, Eclipse becomes unusable and I have to kill the Eclipse process from a terminal.
Any input on how to solve this issue would be greatly appreciated.
UPDATE:
The problem was caused by a non-daemon thread that I'm starting within my init
method (forgot to mention that :). The problem was solved by explicitly stopping the thread with the stop
method, even though that method seems to be deprecated.
As mentioned in this thread, this should be related to a cleanup issue.
If a webapp doesn't cleanup completely, especially with respect to stopping non-daemon threads it starts, Tomcat will fail to shutdown.
Clicking "Stop" has the advantage of providing a timeout.
If Tomcat fails to stop within the timeout, a dialog will appear giving you the option to terminate the server or continue waiting.
Open Command Prompt or PowerShell in windows and type
netstat -nao
find pid of corresponding port from the result and type
taskkill /f /pid [port number]
I was looking at your update which solved your problem also , for all others viewers of this question I want to give better approach.
Instead of using stop u should call interrupt on the thread and wrap code of run method in while loop which checks on !isInterrupted() , whenever interrupt is called thread will come out of loop and run method will complete its processing. Like the below example from my another answer
class Consumer implements Runnable{
private BlockingQueue<Message> blockingQueue;
Consumer(BlockingQueue<Message> blockingQueue){
this.blockingQueue=blockingQueue;
}
@Override
public void run(){
while(!Thread.interrupted()){
System.out.print("Concumer Started");
try{
Message message = blockingQueue.take();
System.out.print("message Id"+message.messageId+" Consumed ");
}
catch(InterruptedException e){
e.printStackTrace();
}
System.out.println("Concumer Done");
}
}
}
On Windows, open Task Manager and kill the process javaw
.
Examples:
taskkill /pid 1230 /pid 1241 /pid 1253
taskkill /f /fi "USERNAME eq NT AUTHORITY\SYSTEM" /im notepad.exe
taskkill /s srvmain /f /im notepad.exe
taskkill /s srvmain /u maindom\hiropln /p p@ssW23 /fi "IMAGENAME eq note*" /im *
taskkill /s srvmain /u maindom\hiropln /fi "USERNAME ne NT*" /im *
taskkill /f /fi "PID ge 1000" /im *
Please use this link https://technet.microsoft.com/en-us/library/bb491009.aspx
I had a similar behaviour. If closing Tomcat doesn't help try to find another active console from console view and kill it. In my case it helps.
On Mac OS X, use Activity Monitor, force quit GrailsStarter process.
精彩评论