Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat Problem :java.net.BindException: Address already in use <null>:8080 at org.apache.tomcat.util.net.JIoEndpoint.init(JIoEndpoint.java:549)

Tags:

java

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 }}}}}}}}}}}}}}");
}

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

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)

please help me to resolve

Thank in advance

like image 419
Chitresh Avatar asked Dec 14 '25 12:12

Chitresh


1 Answers

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.

like image 104
Melv Avatar answered Dec 17 '25 02:12

Melv