1

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));

        }
    }
smolarek999
  • 509
  • 1
  • 5
  • 21
  • Possible duplicate of [Is it possible to read from a InputStream with a timeout?](http://stackoverflow.com/questions/804951/is-it-possible-to-read-from-a-inputstream-with-a-timeout) – André Stannek Oct 07 '15 at 08:36
  • NFS timemouts are a problem dating back 30 years. It is my *very* considered opinion that applications should not use shared file systems in any way. – user207421 Oct 07 '15 at 09:38

0 Answers0