一尘不染

Tomcat问题:java.net.BindException:地址已在使用中 :8080 at org.apache.tomcat.util.net.JIoEndpoint.init(JIoEndpoint.java:549)

tomcat

我正在使用tomcat作为我的网络服务器。我有需要用户单击“编辑”按钮后需要重新启动tomcat服务器的应用程序。为此,我在控制器上编写了如下代码:

if (updateResult ==1) 
{
   //String command = "/home/sunil_shiwankar/Tempo/apache-tomcat-6.0.32/startup.sh";//for linux use .sh
    String command = this.getClass().getResource("/").getPath();
    System.out.println("{{{{{{{{{{{{{{{{{{{{{{{{{{{"+ command);
    command = command.replace(command.substring(command.lastIndexOf("webapps"), command.length()), "");
    System.out.println("{{{{{{{{{{{{{{{{{{{{{{{{{{{ AFTER MODIFYING COMMAND IS "+ command);
    try
    {
      String shutDownCommand = command+"bin/shutdown.sh";
      Process child = Runtime.getRuntime().exec(shutDownCommand);
      System.out.println("{{{{{{{{{{{{{{{{{{{{{{{{{{{ SHUTDOWN TOMCAT SUCCESSFULLY }}}}}}}}}}}}}}");
    } catch (Exception e) 
    {
        String inExceptionStartCommand = command+"bin/startup.sh";
        Process child = Runtime.getRuntime().exec(inExceptionStartCommand);
        System.out.println("{{{{{{{{{{{{{{{{{{{{{{{{{{{ TOMCAT STARTED WITH EXCEPTION SUCCESSFULLY }}}}}}}}}}}}}}");
        e.printStackTrace();
    }
        String normalStartCommand = command+"bin/startup.sh"; 
        Process child = Runtime.getRuntime().exec(normalStartCommand);
        System.out.println("{{{{{{{{{{{{{{{{{{{{{{{{{{{ TOMCAT STARTED WITOUT EXCEPTION SUCCESSFULLY }}}}}}}}}}}}}}");
}

我的tomcat版本6.0.32,在运行我的应用程序时,它会关闭tomcat服务器,并以异常开头

java.net.BindException: Address already in use <null>:8080
    at org.apache.tomcat.util.net.JIoEndpoint.init(JIoEndpoint.java:549)
    at org.apache.coyote.http11.Http11Protocol.init(Http11Protocol.java:176)
    at org.apache.catalina.connector.Connector.initialize(Connector.java:1022)
    at org.apache.catalina.core.StandardService.initialize(StandardService.java:703)
    at org.apache.catalina.core.StandardServer.initialize(StandardServer.java:838)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:538)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:562)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:261)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.net.BindException: Address already in use
    at java.net.PlainSocketImpl.socketBind(Native Method)
    at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:365)
    at java.net.ServerSocket.bind(ServerSocket.java:319)
    at java.net.ServerSocket.<init>(ServerSocket.java:185)
    at java.net.ServerSocket.<init>(ServerSocket.java:141)
    at org.apache.tomcat.util.net.DefaultServerSocketFactory.createSocket(DefaultServerSocketFactory.java:50)
    at org.apache.tomcat.util.net.JIoEndpoint.init(JIoEndpoint.java:538)
    ... 12 more
16 Mar, 2011 10:17:43 AM org.apache.catalina.core.StandardService initialize
SEVERE: Failed to initialize connector [Connector[HTTP/1.1-8080]]
LifecycleException:  Protocol handler initialization failed: java.net.BindException: Address already in use <null>:8080
    at org.apache.catalina.connector.Connector.initialize(Connector.java:1024)
    at org.apache.catalina.core.StandardService.initialize(StandardService.java:703)
    at org.apache.catalina.core.StandardServer.initialize(StandardServer.java:838)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:538)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:562)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:261)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)

请帮我解决

预先感谢


阅读 612

收藏
2020-06-16

共1个答案

一尘不染

该代码虽然很难阅读,但似乎并没有等待关闭发生。我怀疑当您尝试重新启动它时,它仍处于关闭过程中。当然,该异常表明它仍在运行,因为它的http端口仍在使用中。要暂时跟踪问题,请尝试在关闭和启动之间进行睡眠,以查看问题是否解决。

2020-06-16