void (final File directory, final Predicate<File> directoryConsumer, final Consumer<File> fileConsumer) { if (!directoryConsumer.test(directory)) { throw new AssertionError("Code bug: " + directory + " must be a directory"); } final List<RecursiveAction> subDirectoryActions = new ArrayList<>(); final List<File> files = new ArrayList<>(); for (File child : directory.listFiles()) { if (child.isDirectory()) { final RecursiveAction action = new RecursiveAction() { @Override protected void compute() { scanDirectoryWithListFilesFJP(child, directoryConsumer, fileConsumer); } }; action.fork(); subDirectoryActions.add(action); } else { files.add(child); } } for (File file : files) { fileConsumer.accept(file); } for (RecursiveAction action : subDirectoryActions) { action.join(); } }