Creating a Self-Interrupting ExecutorService
===

I've got a task working over a directory of files which needs to throw an IOException if anything goes wrong. I also need it to go faster, so I'm splitting the work done into multiple threads and awaiting their termination. It looks something like this:

    //Needs to throw IOException so the rest of the framework handles it properly.
    public void process(File directory) throws IOException {
        ExecutorService executorService =
            new ThreadPoolExecutor(16, 16, Long.MAX_VALUE, TimeUnit.NANOSECONDS,
                new LinkedBlockingQueue<Runnable>());
        
        //Convenience class to walk over relevant file types.
        Source source = new SourceImpl(directory);
        while (source.hasNext()) {
            File file = source.next();
            executorService.execute(new Worker(file));
        }
        
        try {
            executorService.shutdown();
            executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
        } catch (InterruptedException e) {
            executorService.shutdownNow();
            throw new IOException("Worker thread had a problem!");
        }
    }

While the Worker thread is basically:

    private class Worker implements Runnable {
        private final File file;
        public Worker(File file) { this.file = file; }
        
        @Override
        public void run() {
            try {
                //Do work
            } catch (IOException e) {
                Thread.currentThread().interrupt();
            }
        }
    }

The desired behavior is that if any Worker has an IOException then the spawning thread is made aware of it and can in turn throw its own IOException. This was the best way I could think of to allow the Worker threads to signal an error, but I'm still not sure I set it up right.

So, first of all, will this do what I'm expecting? If a Worker thread has an error in run(), will calling `Thread.currentThread().interrupt();` cause an InterruptedException to be thrown such that it's caught by the blocking `executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);`?

Secondly, what will happen if a running Worker calls its interrupt before all of the threads have been queued; before the blocking try/catch block?

Finally (and most importantly), is there any more elegant way to achieve my aim? I want to have all innumerable subthreads execute either until completion or until any one of them has an error, at which point I'd like to handle it in the spawning thread (by effectively failing the entire directory).