Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception problem: Too many open files  RSS feed

 
Ben Wood
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I have a little program that works on a big grid of data (like a 2D array), by passing in two parameters it should return the closest data point from the grid file, which is accessed using RandomAccessFile. I need to do this in a loop about 1 million times, but after a few thousand iterations I get java.io.IOException: Too many open files.

In the code that accesses the grid file (which is done once per loop) I am calling the close() method each time, and I am not using multiple threads or anything. Can anyone enlighten me as to the possible root cause of this exception please?
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would bet that your program is skipping the close() call. Are you ABSOLUTELY certain that close() gets called for every file created? Make a counter that gets incremented every time a file is created and decremented every time close() gets called.
Are exceptions occuring during the normal processing of your file (i.e. bounds checking)? Do you have close() in a finally block? If not, that is a common cause of such a leak.
 
Ben Wood
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Joe. Tracked it down...I was missing instances of an reasonably commonly occurring exception where the parameters of the query exceeded the range of the available data in the grid file further up in the class scope which was then skipping the close() call. It's now up to 150000 iterations so finger's crossed.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!