taskExecutor.setAsyncMode(false);
// Indicate to the task executor to maintain parallelism
taskExecutor.setMaintainsParallelism(true);
/* Create a Phaser */
Phaser phaser = new Phaser(alphabet.length());
/* Create tasks */
List<FileCounterRecursiveTaskWithPhaser> tasks = new ArrayList<FileCounterRecursiveTaskWithPhaser>(alphabet.length());
for (char c : alphabet.toCharArray()) {
tasks.add(new FileCounterRecursiveTaskWithPhaser(new File(c + ":\\"), phaser));
}
/* Launch tasks */
for (FileCounterRecursiveTaskWithPhaser task : tasks) {
taskExecutor.execute(task);
}
/*
* Wait tasks termination using the Phaser and then display processing
* state
*/
// There only 1 phase in our sample (phase start from zero)
phaser.awaitAdvance(0);
/* Display tasks processing state */
int i = 0;
for (FileCounterRecursiveTaskWithPhaser task : tasks) {
System.out.printf(" ** Task for drive [%s:\\] processing status **\n", alphabet.charAt(i));