java.net.BindException: Address already in use: JVM_Bind is a common exception in Java with applications 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.
In 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
1. 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.
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:
Hello there, I am getting below exception, do you know what causing it :
ReplyDeleteCaused by: java.rmi.server.ExportException: Port already in use: 23602; nested exception is:
java.net.BindException: Address already in use
at sun.rmi.transport.tcp.TCPTransport.listen(TCPTransport.java:310)
at sun.rmi.transport.tcp.TCPTransport.exportObject(TCPTransport.java:218)
INFO 2013-07-17 12:26:44,447 [main] com.mulesoft.habitat.agent.AnypointAgentUtils: Anypoint Service Registry Agent is DISABLED. Property anypoint.agent.token is missing or empty.
ReplyDeleteException in thread "Thread-0" java.lang.RuntimeException: Cannot open port 6666
at com.mulesoft.mule.debugger.remote.RemoteDebuggerServer.createServerSocket(RemoteDebuggerServer.java:83)
at com.mulesoft.mule.debugger.remote.RemoteDebuggerServer.run(RemoteDebuggerServer.java:33)
Caused by: java.net.BindException: Address already in use: JVM_Bind
at java.net.DualStackPlainSocketImpl.bind0(Native Method)
at java.net.DualStackPlainSocketImpl.socketBind(Unknown Source)
at java.net.AbstractPlainSocketImpl.bind(Unknown Source)
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 com.mulesoft.mule.debugger.remote.RemoteDebuggerServer.createServerSocket(RemoteDebuggerServer.java:81)
... 1 more
Very useful information.Thanks a lot
ReplyDeleteHello, I am getting Exception in thread "main" java.net.BindException: Address already in use: JVM_Bind, while running my server. I checked its not running already, but I am still getting this error, does Java keeps the port even after process is killed ?
ReplyDeleteException in thread "main" java.net.BindException: Address already in use: JVM_Bind
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.socketBind(Unknown Source)
at java.net.PlainSocketImpl.bind(Unknown Source
Thanks for the post, that was really helpful.
ReplyDeleteTo kill the port use
Windows
REM find the pid
netstat -a -o -n
taskkill /F /PID
Linux
fuser -k 8080/tcp
or
netstat -anp tcp | grep 8080
kill -9 PID
or
lsof -i tcp:8080
kill -9 PID
@Anonymous, thanks for sharing commands to find the kill a process using a certain port, which is also key to solve this error.
ReplyDeleteFirst time it won't show any error.For the second time executing the same program, you have to close the first one which is running using the same port number.
ReplyDeletein eclipse and netBeans IDE you can find the option called close in the right bottom corner.
It worked for me..Hope it will work for you too......