Address already in use: JVM_Bind java

JavaWeb ApplicationsJbossStruts

Java Problem Overview


Some times whenever I restart the application, which is built on Java Struts Mysql and Jboss 4.05 Version I get the error as Address already in use: JVM_Bind

Only fix that i know is to restart the machine and try again, it will work. Else Some times I do Ctrl-Alt-Del and Stop all the process related to Java, some times this also works.

But what is the exact reason and how can we prevent this problem ?

Java Solutions


Solution 1 - Java

> Address already in use: JVM_Bind

means that some other application is already listening on the port your current application is trying to bind.

what you need to do is, either change the port for your current application or better; just find out the already running application and kill it.

on Linux you can find the application pid by using,

netstat -tulpn

Solution 2 - Java

In windows this scenario happens when Eclipse crashes without a clean shutdown it will have the local Jetty or Tomcat server keep running. When you reopen Eclipse and try to start server again this will lead to the "Address already in use: JVM_Bind"

You can solve this by opening Task Manager and find the javaw.exe process and ending it.

Then you can restart the server on Eclipse.

enter image description here

Solution 3 - Java

I usually come across this when the port which the server (I use JBoss) is already in use

Usual suspects

  1. Apache Http Server => turn down the service if working in windows.
  2. IIS => stop the ISS using
  3. Skype =>yea I got skype attaching itself to port 80

To change the port to which JBoss 4.2.x binds itself go to:

> "C:\jboss4.2.2\server\default\deploy\jboss-web.deployer\server.xml"

here default is the instance of the server change the port here :

> <Connector port="8080" > address="${jboss.bind.address}" >

In the above example the port is bound to 8080

Solution 4 - Java

Open command line and type: netstat -a -o -n or tasklist to see currently running processes. Find port that related to Java and type: taskkill /F /PID <your PID number>. Click Enter.

Solution 5 - Java

Is it possible that MySql listening on the same port as JBoss?

Is there a port number given in the error message - something like Address already in use: JVM_Bind:8080

You can change the port in JBoss server.xml to test this.

Solution 6 - Java

On windows, in an elevated cmd/ps

net stop winnat

then

net start winnat

Resets the windows' NAT service and that removes faulty listeners. This method works for most 'cannot listen on this port' errors, like as in Docker, JVM etc.

Solution 7 - Java

The quick answer on how to prevent it is that you most likely need to stop JBoss before starting it again.

You should be able to call the "Terminate" button in the Console view to shutdown the server.

Solution 8 - Java

That error means that the you are trying to create a new ServerSocket on a port already in use by another ServerSocket. So try to make your application closing all sockets and connections you know about and be sure your application is completely terminated. Also check if there is another proces you launched by your program.

Solution 9 - Java

It can be also caused by double definition of port 8080 in ..\tomcat\conf\server.xml :

<Connector port="8080"
           enableLookups="false" redirectPort="8443" debug="0"/>
<Connector port="8080"
           enableLookups="false" address="127.0.0.1" maxParameterCount="30000"/>

Solution 10 - Java

please try following options for JVM binding exception:

  1. start and stop the server. and check the server process ids and kill and stop the server.
  2. go to control panel->administrative tool-> service-> check all server and stop all the servers and then start your own server.
  3. change the Browser which your using. for example if your using IE ,change it to Mozilla firefox.

Solution 11 - Java

I was having this problem too. For me, I couldn't start/stop openfire (it said it was stopped, but everything was still running)

sudo /etc/init.d/openfire stop
sudo /etc/init.d/openfire start

Also, restarting apache did not help either

sudo /etc/init.d/apache2 restart

The errors were inside:

/opt/openfire/logs/stderror.log
Error creating server listener on port 5269: Address already in use
Error creating server listener on port 5222: Address already in use

The way I fixed this, I had to actually turn off the server inside the admin area for my host.

Solution 12 - Java

I had the same on Windows. My solution was to get which port the debug wants to connect to. (In IntelliJ a red rectangle already giving the info: "Error running Tomcat: Unable to open debugger port (127.0.0.1:XXXXX): ... Already in use...") Let's say XXXXX is the port number. Then i searched for the problem and the PID in a cmd window:

netstat -ano | find "CLOSE_WAIT" | find ":XXXXX"

I got the PID number as the last number in the result line. (Let's say YYYY) Finally:

TASKKILL /PID YYYY

An extra info: Winscp logged out meanwhile, probably it was causing my problem. :)

Solution 13 - Java

This recently happen to me when enabling JMX on two running tomcat service within Eclipse. I mistakenly put the same port for each server.

Simply give each jmx remote a different port

Server 1

-Dcom.sun.management.jmxremote.port=9000

Server 2

-Dcom.sun.management.jmxremote.port=9001

Solution 14 - Java

You can try deleting the Team Server credentials, most likely those will include some kind of port in the server column. Like https://wathever.visualstudio.com:443

Go to Windows/Preferences expand Team then Team Foundation Server go to Credentials and remove whichever is there.

Solution 15 - Java

On Mac, even when I'd search with netstat, no processes were binding to that port, but I'd still get the "Address already in use" Bind exception.

In this case, going into

Safari -> Preferences -> Privacy -> Manage Website Data... -> finding "localhost" -> Remove

fixes the problem, if there really is no process running with that port. It seems Safari's web cache maintains a reference to the port somehow, and removing that cache frees up the port.

Solution 16 - Java

Sometimes, I use lsof -i:8080 and I get nothing back, no pid. Well something has to be taking place. If this is your case, it could be docker. By using docker ps you can check if you have any old dockers lying around and kill them. This could be the culprit for a port already in use error.

Solution 17 - Java

For the sake of completeness as many may fall in this SO for other reasons than OP's question, here is another info that saved my day :

TL;DR;
Check that the port you want to open is not reserved (even though no application has opened it)
On windows :
netsh interface ipv4 show excludedportrange protocol=tcp

Explanation :
At least on windows, another possible cause for the java.net.BindException: Address already in use: JVM_Bind is that the operating system has "reserved" the port.
If you use the commands from other answer in this topic, they will tell you that no application is listening to the port, yet you cannot open it.

Some windows update like this one reserves range port that can then no longer be claimed by processes.
Though not explicit on the port that can no longer be opened, the update note mentions a command that can help troubleshooting the issue :

netsh interface ipv4 show excludedportrange protocol=tcp

this will yield a list of port range that are blocked :

Protocol tcp Port Exclusion Ranges

Start Port    End Port
----------    --------
5357        5357
49709       49808
49809       49908
49909       50008
50009       50108
50109       50208
50280       50379

* - Administered port exclusions.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiongmhkView Question on Stackoverflow
Solution 1 - Javaphoenix24View Answer on Stackoverflow
Solution 2 - JavaCodeQView Answer on Stackoverflow
Solution 3 - JavafrictionlesspulleyView Answer on Stackoverflow
Solution 4 - JavaTaras MelnykView Answer on Stackoverflow
Solution 5 - JavaJoseKView Answer on Stackoverflow
Solution 6 - Javacryo._View Answer on Stackoverflow
Solution 7 - JavaJarle HansenView Answer on Stackoverflow
Solution 8 - JavaMartijn CourteauxView Answer on Stackoverflow
Solution 9 - JavaSzBView Answer on Stackoverflow
Solution 10 - JavaaarifmkhanView Answer on Stackoverflow
Solution 11 - JavabusytrainingView Answer on Stackoverflow
Solution 12 - JavaBlondCodeView Answer on Stackoverflow
Solution 13 - JavasteveView Answer on Stackoverflow
Solution 14 - Javauser9203842View Answer on Stackoverflow
Solution 15 - JavaEpagaView Answer on Stackoverflow
Solution 16 - JavaLaptopProfileView Answer on Stackoverflow
Solution 17 - JavaGhurdylView Answer on Stackoverflow