Is this possible to specify any kind of timeout to java I/O operations?
We have a situation where our NFS filesystem freeze and then call to FileOutputStream.write() also freeze. With the timeout on, we may detect such situation and do some action.
===============
One solution which come to my mind is to run some kind of check on thread pool and wait for result with timeout. But i'm not sure what will happen with this callable, it may hang and do not release file descriptors etc..
taskExecutor.submit(new FilesystemCheck(filepath)).get(timeout, TimeUnit.SECONDS);
with the callable
public static class FilesystemCheck implements Callable<Boolean> {
private final String path;
public FilesystemCheck(String path) {
this.path = path;
}
@Override
public Boolean call() throws Exception {
return Files.exists(Paths.get(path));
}
}