Home › Java › java.net.BindException: Address already in use — Find the Process and Fix It
Beginner 3 min · November 28, 2026

java.net.BindException: Address already in use — Find the Process and Fix It

BindException: Address already in use means another process is already listening on that port — often the old copy of your own app.

N
Naren Founder & Principal Engineer

20+ years shipping production Java in banking & fintech. Drawn from code that ran under real load.

Follow
✓ Production
production tested
November 28, 2026
last updated
2,141
articles · all by Naren
Before you start⏱ 6 min
  • ✓Basic Java
  • ✓Basic networking
 ● Production Incident 🔎 Debug Guide
⚡Quick Answer
  • Another process is listening on that port.
  • Linux/macOS: lsof -i :8080 or ss -ltnp 'sport = :8080'.
  • Windows: netstat -ano | findstr :8080, then tasklist /FI "PID eq ".
  • Often it's the old instance of your own app still shutting down.
  • Fix restart scripts: stop, wait for the process to exit, then start.
  • Or kill the stale process, or run on another port (server.port=8081).
✦ Definition~90s read
What is java.net.BindException?

java.net.BindException: Address already in use is thrown when a server socket tries to bind to a port that another process is already listening on. Spring Boot reports it as 'Web server failed to start. Port 8080 was already in use.'

★
A port is a single socket on the wall.
Plain-English First

A port is a single socket on the wall. One plug at a time. If the old plug is still in, the new one can't go in.

A restart script started the new orders-api before the old one had finished stopping. Port 8080 was still taken.

Find the Process

Identify who is listening on the port before changing anything.

find.shBASH
1
2
3
4
5
6
lsof -i :8080
# java  4211  app  LISTEN

# Windows
netstat -ano | findstr :8080
tasklist /FI "PID eq 4211"
🎯 Key Takeaway
Know the holder first.

Fix the Restart

Stop, wait for the process to exit, then start.

restart.shBASH
1
2
3
kill "$PID"
while kill -0 "$PID" 2>/dev/null; do sleep 1; done
./start.sh
🎯 Key Takeaway
Never overlap instances.

Or Change the Port

If another application legitimately uses the port, run yours elsewhere.

application.propertiesPROPERTIES
1
server.port=8081
🎯 Key Takeaway
server.port.
● Production incidentPOST-MORTEMseverity: high

The Restart That Overlapped

Symptom
Web server failed to start. Port 8080 was already in use.
Assumption
The team suspected another application had grabbed the port.
Root cause
restart.sh sent stop and immediately started the new instance; the old one needed ~8 s to shut down.
Fix
The script now waits for the old PID to exit before starting.
Key lesson
  • One listener per port.
  • Wait for exit before start.
  • Find the holder with lsof/netstat.
Production debug guideWho holds it?3 entries
Symptom · 01
Linux/macOS
→
Fix
lsof -i :8080
Symptom · 02
Windows
→
Fix
netstat -ano | findstr :8080
Symptom · 03
Only during restarts
→
Fix
Overlapping instances: wait for exit.
⚙ Quick Reference
3 commands from this guide
FileCommand / CodePurpose
find.shlsof -i :8080Find the Process
restart.shkill "$PID"Fix the Restart
application.propertiesserver.port=8081Or Change the Port

Key takeaways

1
One listener per port.
2
lsof / netstat to find it.
3
Stop, wait, start.
4
Or change the port.

Common mistakes to avoid

2 patterns
×

Starting before the old process exits

Symptom
Bind fails on every restart.
Fix
Wait for exit.
×

Killing without checking

Symptom
Stopped someone else's service.
Fix
Identify the PID's owner first.
INTERVIEW PREP · PRACTICE MODE

Interview Questions on This Topic

Q01JUNIOR
What causes BindException: Address already in use?
Q01 of 01JUNIOR

What causes BindException: Address already in use?

ANSWER
Another process is already listening on that address and port.
FAQ · 2 QUESTIONS

Frequently Asked Questions

01
How do I free port 8080?
02
Port 8080 was already in use Spring Boot?
N
Naren Founder & Principal Engineer

20+ years shipping production Java in banking & fintech. Drawn from code that ran under real load.

Follow
✓ Verified
production tested
November 28, 2026
last updated
2,141
articles · all by Naren
🔥

That's Exceptions. Mark it forged?

3 min read · try the examples if you haven't

←
Previous
java.net.UnknownHostException
14 / 14 · Exceptions
Next
ADB Device Unauthorized Fix
→