Java Tomcat 未在 Eclipse 中关闭

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1998281/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 02:16:26  来源:igfitidea点击:

Tomcat not shutting down within Eclipse

javaeclipsetomcatservlets

提问by Luke

I'm building a relatively simple web-app where the main servlet implements the ServletContextListenerinterface to determine whether the context has been started or stopped. I've implemented my contextInitialized, contextDestroyed, initand destroymethods (both initand destroycall superon the base class). I've currently implemented no real functionality other than that I've initialized log4j in the contextInitializedmethod where I load the log4j.propertiesfile.

我正在构建一个相对简单的 web 应用程序,其中主 servlet 实现ServletContextListener接口以确定上下文是已启动还是已停止。我实现了我的contextInitializedcontextDestroyedinitdestroy方法(包括initdestroy调用super基类)。除了在contextInitialized加载log4j.properties文件的方法中初始化 log4j 之外,我目前没有实现任何真正的功能。

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:

然而,当我从 Eclipse 中启动和停止 Tomcat 服务器时,所有内容都以正确的顺序调用(我正在使用 someSystem.out.println来测试这个),但是在停止服务器大约 10 秒后,我会看到一个 Eclipse 弹出窗口,说明下列:

Server Tomcat v6.0 Server at localhost is not responding. Do you want to terminate this server? Click OK to terminate the server or click Cancel to continue waiting.

服务器 Tomcat v6.0 服务器在 localhost 没有响应。您要终止此服务器吗?单击确定终止服务器或单击取消继续等待。

This is what's printed in my Eclipse console when I stop the server:

这是我停止服务器时在 Eclipse 控制台中打印的内容:

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

04/01/2010 7:39:13 PM org.apache.catalina.core.StandardService 停止
信息:停止服务 Catalina
contextDestroyed
04/01/2010 7:39:13 PM org.apache.coyote.http11.Http11Protocol 销毁
信息:在 http-8080 上停止 Coyote HTTP/1.1

And after the last INFOmessage 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.

在最后INFO一条消息之后,它只是挂在那里,直到弹出窗口出现。如果我选择等待,按取消,Eclipse 将无法使用,我必须从终端终止 Eclipse 进程。

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 initmethod (forgot to mention that :). The problem was solved by explicitly stopping the thread with the stopmethod, even though that method seems to be deprecated.

问题是由我在我的init方法中启动的非守护进程线程引起的(忘了提及:)。该问题已通过使用该stop方法显式停止线程来解决,即使该方法似乎已被弃用。

采纳答案by VonC

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.

如果 webapp 没有完全清理,特别是在停止它启动的非守护线程方面,Tomcat 将无法关闭。
单击“停止”具有提供超时的优点。
如果 Tomcat 未能在超时内停止,则会出现一个对话框,让您选择终止服务器或继续等待。

回答by cetnar

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.

我有类似的行为。如果关闭 Tomcat 无济于事,请尝试从控制台视图中查找另一个活动控制台并杀死它。就我而言,它有帮助。

回答by usayee

On Windows, open Task Manager and kill the process javaw.

在 Windows 上,打开任务管理器并终止进程javaw

回答by hko19

On Mac OS X, use Activity Monitor, force quit GrailsStarter process.

在 Mac OS X 上,使用活动监视器,强制退出 GrailsS​​tarter 进程。

回答by afthab

Open Command Prompt or PowerShell in windows and type

在 Windows 中打开命令提示符或 PowerShell 并键入

netstat -nao

find pidof corresponding port from the result and type

从结果中找到对应端口的pid并输入

taskkill /f /pid [port number] 

回答by Vipin

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

而不是使用 stop 你应该在线程上调用中断并将 run 方法的代码包装在检查 !isInterrupted() 的 while 循环中,每当调用中断时,线程将退出循环并且 run 方法将完成其处理。就像我另一个答案中的以下示例一样

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");
        }
    }
}

回答by Java_Fire_Within

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

请使用此链接 https://technet.microsoft.com/en-us/library/bb491009.aspx