zoukankan      html  css  js  c++  java
  • Use TCPView to resolve "Address already in use: bind" issue

    When we run a runnable JAR file multiple times from the console, it's common that we would run into the following exception error:

    PS C:UsersxingzhouDesktopJettyApplication> java.exe -jar .FileServer.jar
    2016-11-07 13:39:28.401:INFO::main: Logging initialized @367ms
    2016-11-07 13:39:28.569:INFO:oejs.Server:main: jetty-9.3.z-SNAPSHOT
    Exception in thread "main" java.net.BindException: Address already in use: bind
            at sun.nio.ch.Net.bind0(Native Method)
            at sun.nio.ch.Net.bind(Unknown Source)
            at sun.nio.ch.Net.bind(Unknown Source)
            at sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source)
            at sun.nio.ch.ServerSocketAdaptor.bind(Unknown Source)
            at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:317)
            at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
            at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:235)
            at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
            at org.eclipse.jetty.server.Server.doStart(Server.java:390)
            at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
            at org.eclipse.jetty.embedded.FileServer.main(FileServer.java:35)

    The exception is obvious, that the configured port is in use by some other process. In this case, it is "8080" since we have the following code in the Main function.

    public static void main(String[] args) throws Exception{
            // TODO Auto-generated method stub
            // Create a basic Jetty server object that will listen on port 8080.  Note that if you set this to port 0
            // then a randomly available port will be assigned that you can either look in the logs for the port,
            // or programmatically obtain it for use in test cases.
            Server server = new Server(8080);
            
    ...
        }

    Now, how to resolve this issue?

    Firstly, we can use TCPView to check which process is listening this port.

    (TCPView is a Windows program that will show you detailed listings of all TCP and UDP endpoints on your system, including the local and remote addresses and state of TCP connections.)

    Here I simply kill the process 5912 to move on.

    Another way to resolve this issue is using netstat command:

    PS C:UsersxingzhouDesktopJettyApplication> netstat -ano | findstr "8080"
      TCP    0.0.0.0:8080           0.0.0.0:0              LISTENING       27560
      TCP    [::]:8080              [::]:0                 LISTENING       27560
    PS C:UsersxingzhouDesktopJettyApplication> tasklist | findstr "27560"
    javaw.exe                    27560 Console                    1     35,680 K
    PS C:UsersxingzhouDesktopJettyApplication> kill 27560
    PS C:UsersxingzhouDesktopJettyApplication> tasklist | findstr "27560"
  • 相关阅读:
    魅族note手机 图片打马赛克
    魅蓝note手机一键root
    eclipse启动时return code 13
    Eclipse adt 23中运行百度地图官网上的demo出现fatal错误
    windows上部署svn服务器
    windows下jenkins slave 搭建
    图片懒加载
    tomcat7 设置静态资源的expires过期时间
    如何将不带www的根域名301重定向到带www的主域名
    简单的防止图片另存为
  • 原文地址:https://www.cnblogs.com/xingzhou/p/6038969.html
Copyright © 2011-2022 走看看