简体   繁体   English

Netbeans Run-> Stop Build不会停止正在运行的Java进程

[英]Netbeans Run->Stop Build does not stop the running java processes

I'm using Netbeans 7.1.2 on Mac OS X Lion 10.7.3. 我在Mac OS X Lion 10.7.3上使用Netbeans 7.1.2。

I have a simple java server (using netty) project and after I build and run the project then try to stop the running by Run->Stop Build it does not terminate the java server process. 我有一个简单的Java服务器(使用netty)项目,在构建并运行该项目后,尝试通过Run-> Stop Build停止运行,它不会终止Java服务器进程。

For example, my server app uses port 8080 and even after I stop running from the netbeans the port 8080 is in use and the app keeps running. 例如,我的服务器应用程序使用端口8080,甚至在我停止从netbeans运行后,端口8080仍在使用中,并且该应用程序继续运行。 I have to manually kill the java process from activity monitor. 我必须从活动监视器中手动杀死Java进程。

What's the correct procedure to end the running app started by Netbeans? 结束Netbeans启动的正在运行的应用程序的正确过程是什么?

Greatly appreciate your help. 非常感谢您的帮助。 Thanks in advanced. 提前致谢。

Have a look at the documentation: http://netty.io/docs/stable/guide/html/ . 看一下文档: http : //netty.io/docs/stable/guide/html/ Scroll down to section 9. Shutting Down Your Application. 向下滚动到部分9。关闭您的应用程序。

Your main app ahs to look something like: 您的主要应用程序看起来像:

package org.jboss.netty.example.time;
public class TimeServer {
    static final ChannelGroup allChannels = new DefaultChannelGroup("time-server"(35));
    public static void main(String[] args) throws Exception {
        ...
        ChannelFactory factory = ...;
        ServerBootstrap bootstrap = ...;
        ...
        Channel channel = bootstrap.bind(...);
        allChannels.add(channel);

        ...

        // Shutdown code
        ChannelGroupFuture future = allChannels.close();
        future.awaitUninterruptibly();
        factory.releaseExternalResources();
    }
}

You handler needs: 您的处理程序需要:

public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) {
    TimeServer.allChannels.add(e.getChannel());
}

You have to: 1. Store all your channels in a ChannelGroup 2. When shutting down, close all channel and release resources. 您必须:1.将所有通道存储在ChannelGroup .关闭时,关闭所有通道并释放资源。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM