private FileStatus [ ] concurrentGlobInternal ( Path fixedPath , PathFilter filter ) throws IOException { ExecutorService executorService = Executors . newFixedThreadPool ( 2 , DAEMON_THREAD_FACTORY ) ; Callable < FileStatus [ ] > flatGlobTask = ( ) -> flatGlobInternal ( fixedPath , filter ) ; Callable < FileStatus [ ] > nonFlatGlobTask = ( ) -> super . globStatus ( fixedPath , filter ) ; try { return executorService . invokeAny ( Arrays . asList ( flatGlobTask , nonFlatGlobTask ) ) ; } catch ( InterruptedException | ExecutionException e ) { throw ( e . getCause ( ) instanceof IOException ) ? ( IOException ) e . getCause ( ) : new IOException ( e ) ; } finally { executorService . shutdownNow ( ) ; } }
Use 2 glob algorithms that return the same result but one of them could be significantly faster than another one depending on directory layout .