Kamis, 20 Maret 2014

Java.net.BindException: Address already in use: JVM_Bind:8080 Solution




java.net.BindException: Address already in use: JVM_Bind is a common exception in Java with application trying to connect on a particular port and some other processes either Java or non Java is already connected on that port. You can get "Address already in use: JVM_Bind" error while doing remote debugging in Java in Eclipse, when Eclipse trying to connect to remote Java application, when you are starting tomcat and another instance of tomcat is listening on port 8080 you will get java.net.BindException: Address already in use: JVM_Bind:8080.





Address already use: JVM Bind ExceptionIn this post we will analyze java.net.BindException and trying to figure out cause of "Address already in use: JVM_Bind" before fixing it. This article is in continuation of my earlier tutorial, How to Solve OutOfMemoryError in Java and How to fix ClassNotFoundException in Java.






How to deal with java.net.BindException: Address already in use: JVM_Bind:8080




Address already in use: JVM_Bind:8080



This exception is self explanatory, its saying that a Java application is trying to connect on port 8080 but that port is already used by some other process and JVM Bind to that particular port, here its 8080, is failed. Now to fix this error you need to find out which process is listening of port 8080, we will how to find a process which is listening on a particular port in both windows and Linux.





Find process which is listening on port 8080 in Windows netstat command is your friend, just use netstat with find command  as shown in below example:






C:\>netstat -ano | find "8080"


TCP    0.0.0.0:8080           0.0.0.0:0              LISTENING       26732






Last column is PID of process which is listening on port "8080”, possibly a tomcat web server. You can verify it by looking into task manager and displaying PID as column.





Find process which is listening on port 8080 in Linux


Great thing is that you can use netstat command in Linux and UNIX as well, though with little difference in option it can show you process listening on a particular port, instead of "-o" I normally use "-p" and then use UNIX grep command to select particular process with PID.






trader@asia:~ netstat -nap | grep 8080








How to solve "java.net.BindException: Address already in use"



Now since you have find out offending process you can kill that process and restart yours if killing that process is OK, otherwise change the port your web server is using and you will not get "java.net.BindException: Address already in use" Exception, but if you can not kill that process than you need to change your web-server configuration or eclipse configuration to listen on different port. In case of tomcat you can change it on connector section of server.xml and in case of eclipse you can see here setting up Eclipse for Java remote debugging.





Common Scenario when you see "Address already in use: JVM_Bind"


1. While doing Java remote debugging in Eclipse and when Eclipse tries to connect your remote java application on a particular port and that port is not free.





2. Starting tomcat when earlier instance of tomcat is already running and bonded to 8080 port. It will fail with SEVERE: Error initializing endpoint java.net.BindException: Address already in use: JVM_Bind:8080


3. "Address already in use jvm_bind" could also comes up with other web and application servers like weblogic, glassfish and webshere.





I don't remember count how many times I have got Address already in use: JVM_Bind ERROR but most of the time it turns out that another instance of same process is running and listening on same port,So watch for it and it can save time for you. Some time this is also called "port already in use JVM_Bind" so don't confuse Address and port is used interchangeably in different places.





Related Java Tutorials:






























Source:http://javarevisited.blogspot.com/2011/12/address-already-use-jvm-bind-exception.html

Tidak ada komentar:

Posting Komentar