0

There is a java program which read files from a folder, do some processing and write output files in another folder. It ran for 4 hours and produced few files but then failed after throwing following error:

"too many files"

Then I modified the program to close everything (BufferReader and BufferWriter) and started the process again. But this time process failed just after starting by throwing following error:

java.io.FileNotFoundException: <file> (Too many open files)

Then i tried running lsof and searched for the process which is having most no of open files. I realized it is NetworkManager. But I was not sure whether i should kill that process or not. So I restarted the machine. Even after that when I ran java program, I still got the same error.

In worst case it might be possible that my code is still having some leaks in terms of not closing everything, but still it is failing now just after starting the process. So I have a feeling that something is lying in system from previous run. Also If I start same process in some other machine, it runs for hours before failing.

Shweta
  • 1,111
  • 3
  • 15
  • 30

1 Answers1

1

You cannot retain a resource between runs of a program, even if you wanted to. You could leave your system without enough resources in theory, though unlikely, but restarting the machine should fix that.

What is more likely is that the files you have is enough to trigger the program to run out of file handles. Try renaming the directory you store the files in and starting with an empty one to confirm this.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130