Hi, I use a lot of temporary files in java and my problem is that they are not deleted.
Without having to do my own temporary file management processing (it's not difficult I give you, but I'm a lazy plus with so many things to do, if I can save the reinvented wheel for this, the better) is there a way to provide temporary files to disk will be removed in a fairly normal way.
1 - using File tmp = File.createTempFile (), I can say tmp.deleteOnExit (), but if a thing works in the service, the only way to exit it is when it either crashes (rarely occurs) or when system crashes (for example, when the drive is completely full of temporary files and overthrows the cluster ... oops!)
Ideally, the created instances are collected at some point by the garbage collector, and since there is a lot of downtime in the application, it would just be a dandy if the GC could, well, finish cleaning it up and actually delete the file on disk, as well as dereferencing instance from memory.
The only way that I can see at the moment is to overload the File class and add a finalized method ... If I do this, I will also take care of my own temp file manager!
In short, can I use the garbage collector to clean up system resources (like files)?
Thank you all for your answers. I accepted Kristofffer because it was the easiest to implement, and that is exactly what I did.
I think that they cleaned me after so many years, making me forget about the basic household that I was, although I did the hard way in the days of C ++ goodwill.
java garbage-collection temporary-files
Newtopian
source share