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"
  • 相关阅读:
    MS SQL Server备份与恢复实例
    如何加快查询,优化数据库
    使用索引的误区之一:没有使用复合索引的前导列导致查询不使用索引
    URL重写可删节日期模式正则表达式之强力应用
    索引全攻略
    大数据量分页存储过程效率测试附代码
    形成查询结果(实体框架) 使用导航属性导航关系
    C#开源资源大汇总
    大数据量的系统的数据库结构如何设计?
    数据库查询优化
  • 原文地址:https://www.cnblogs.com/xingzhou/p/6038969.html
Copyright © 2011-2022 走看看