Friday, April 6, 2012

How to get rid of "Address already in use: JVM_Bind" in windows OR linux


You may get below errors in your server console on your server startup.

SEVERE: Failed to initialize end point associated with ProtocolHandler ["http-bio-8080"]
java.net.BindException: Address already in use: JVM_Bind :8080
 at org.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:378)
 at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:483)
 at org.apache.coyote.AbstractProtocolHandler.init(AbstractProtocolHandler.java:345)
 at org.apache.coyote.http11.AbstractHttp11JsseProtocol.init(AbstractHttp11JsseProtocol.java:119)
 at org.apache.catalina.connector.Connector.initInternal(Connector.java:910)
 at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:101)
 at org.apache.catalina.core.StandardService.initInternal(StandardService.java:559)
 at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:101)
 at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:781)
 at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:101)
 at org.apache.catalina.startup.Catalina.load(Catalina.java:572)
 at org.apache.catalina.startup.Catalina.load(Catalina.java:595)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)


Caused by: java.net.BindException: Address already in use: JVM_Bind
 at java.net.PlainSocketImpl.socketBind(Native Method)
 at java.net.PlainSocketImpl.bind(Unknown Source)
 at java.net.ServerSocket.bind(Unknown Source)
 at java.net.ServerSocket.(Unknown Source)
 at java.net.ServerSocket.(Unknown Source)
 at org.apache.tomcat.util.net.DefaultServerSocketFactory.createSocket(DefaultServerSocketFactory.java:48)
 at org.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:365)
 ... 17 more

As the error suggest there is already another server running on the same port (in our case 8080) . you can either kill that service or change your web server to run on another port.
 

1. How to kill previous service.

If you have decided to kill the previous service, then you just have to find the process in which your service is running and simpily kill that process.

Below are the commands to find the process and kill it.

 Window :

 In windows netstat is used to Displays protocol statistics and current TCP/IP network connections. Just find the process which is using the port number. Lets assume the process number is 6324. Then use taskkill command to forcefully terminate that process.

  • netstat -ano | find "8080"
  • taskkill /F /PID 6324


Linux :

Similarly in Linux we can use netstat command to find the process. In linux netstat is used to show network status and grep command is used to find the particular port out of it as shown below. Then use kill command to terminate the process.

  • netstat -an | grep "8080"
  • kill - 6324

2. How to change web server to run on another port.

Tomcat

If you are using tomcat, Just locate the file server.xml (E.g. C:/apache-tomcat-7.0.11/conf/server.xml). You will see below code snippet.

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />


Just change the above port number (E.g. 8080 ) to any other port number. Now your web server will run on the new port which you have provided.

Conclusion :

To get rid of "Address already in use: JVM_Bind" you can either kill that service or change your web server to run on another port.