File.isDirectory() and File.exists() can lock up application
807580Aug 5 2009 — edited Aug 24 2009I've discovered recently that, at least under some circumstances, calling file.isDirectory() and/or file.exists() on a File object can lock up whatever thread it is running in for an unreasonable amount of time (by unreasonable, I'm talking minutes). In my case, the program was attempting to process the root directory of a mapped network drive mapped to a machine that was offline. This was with Java 1.5 running on Windows XP SP3.
In my case, I have a FileUtil class with some various helper methods in it; to this class I added a couple of new methods FileUtil.isDirectory(File file) and FileUtil.exists(File file). Each method uses a FutureTask to implement a timeout on the basic file operations, and returns a Boolean that is null if a timeout occurs. This gets around the long duration lock up that can occur. I can post the code later today if anyone wants to see it (don't have it at my desk right now). I at first considered using a Thread with wait and notify, but for the life of me, I can't figure out how to properly implement a timeout using wait and notify. Either way, I don't like having to use a separate thread every time I want to check if a file exists or is a directory, but for the time being I'm not seeing a better solution.
I'm curious if others have run into this problem, and if so, how did they get around it? Feel free to share.
Edited by: Skotty on Aug 5, 2009 6:08 PM