0

I have to process thousands of files but my program is failing after 20 files with the exception "No Space Left".

This is my pseudo code.

for (Task t: tasks) {
    File f = t.createTempFile()
    processing(f)
    f.delete()
}

I checked the /tmp folder. The files are not getting deleted. My hairs are falling out. Can someone give some suggestions?

PS: it should have permissions to create the files so it should have permissions to delete as well.

user207421
  • 305,947
  • 44
  • 307
  • 483
TrongBang
  • 923
  • 1
  • 12
  • 23
  • 1
    Does your `processing(...)` method work in a background thread, or is it blocking? – Hovercraft Full Of Eels Jan 29 '19 at 01:10
  • 3
    delete will return true if and only if the file or directory is successfully deleted; false otherwise, check the return value – 宏杰李 Jan 29 '19 at 01:12
  • 1
    Where are your semicolons? And where is `Task` defined? – smac89 Jan 29 '19 at 01:20
  • may happen if some large file has been deleted,still opened by some process. Check with the command lsof | grep deleted to see which processes have opened descriptors to deleted files. You can restart the process and the space will be freed. – Sanka Jan 29 '19 at 01:23

1 Answers1

2

It is probably because you still have some input or output stream on the file and you forgot to close it.
If the JVM itself (in any thread) is still holding an input or output stream to the file, it won't be deleted.
As was said in the comment above, you can check the return status of the method as well.

Yoni
  • 10,171
  • 9
  • 55
  • 72