Tomcat 问题:java.net.BindException:org.apache.tomcat.util.net.JIoEndpoint.init(JIoEndpoint.java:549) 上

编程入门 行业动态 更新时间:2024-10-25 02:29:37
本文介绍了Tomcat 问题:java.BindException:org.apache.tomcat.util.JIoEndpoint.init(JIoEndpoint.java:549) 上的地址已在使用中<null>:8080的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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

I am using tomcat as my webserver. i have application which needs a tomcat server restart after click of edit button by user. for that i have written a code on my controller as below:

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 服务器并以异常启动

my tomcat version 6.0.32 and while runing my application it shutdown tomcat server proparly and starts with an exception

java.BindException: Address already in use <null>:8080
    at org.apache.tomcat.util.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.BindException: Address already in use
    at java.PlainSocketImpl.socketBind(Native Method)
    at java.PlainSocketImpl.bind(PlainSocketImpl.java:365)
    at java.ServerSocket.bind(ServerSocket.java:319)
    at java.ServerSocket.<init>(ServerSocket.java:185)
    at java.ServerSocket.<init>(ServerSocket.java:141)
    at org.apache.tomcat.util.DefaultServerSocketFactory.createSocket(DefaultServerSocketFactory.java:50)
    at org.apache.tomcat.util.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.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)

请帮我解决

提前致谢

推荐答案

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

That code, although hard to read, appears to not be waiting for the shutdown to happen. I suspect it's still in the process of shutting down when you try to start it again. Certainly, the exception indicates it's still running, because its http port is still in use. To track the problem down temporarily, try putting a sleep in between the shutdown and startup to see if it fixes the problem.

这篇关于Tomcat 问题:java.BindException:org.apache.tomcat.util.JIoEndpoint.init(JIoEndpoint.java:549) 上的地址已在使用中&lt;null&gt;:8080的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 03:55:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1389358.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:已在   地址   tomcat   apache   util

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!