This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SocketException: Too many open files

 
Andres Delrotti
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Javaranch....I have another problem....

I have a running thread which connect to a socket port of a certain URL and reads incoming messages from the connected host port. The code basically goes like this:

This is done inside the run method of the thread


while (true) {
try {
Socket socket = new Socket(hostname, Integer.parseInt(port));
InputStreamReader input = new InputStreamReader
socket.getInputStreamReader());
BufferedReader in = new BufferedReader(input);
while (connected) {
if (in.ready()){
int charMsg = in.read();
// do processes
}
}
catch (SocketException ex) {
e.printStackTrace();
}
}


If ever the host is down....it catches the SocketException prints the exception and goes back to the nex iteration of the while true loop...until the host becomes available again.

Whenever the host becomes unavailble and I check the stack trace... I always get the Exception: SocketException (too many open files). What could be the cause of this? Can anyone enlighten me on this?
 
Joe Ess
Bartender
Posts: 9311
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This article may help you out
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic