Futures and blocking IO
The choice of using ForkJoinPool for imminent is deliberate. The ForkJoinPool—added on Java 7—is extremely smart. When created, you give it a desired level of parallelism
, which defaults to the number of available processors.
ForkJoinPool then attempts to honor the desired parallelism by dynamically shrinking and expanding the pool as required. When a task is submitted to this pool, it doesn't necessarily create a new thread if it doesn't have to. This allows the pool to serve an extremely large number of tasks with a much smaller number of actual threads.
However, it cannot guarantee such optimizations in the face of blocking IO, as it can't know whether the thread is blocking waiting for an external resource. Nevertheless, ForkJoinPool provides a mechanism by which threads can notify the pool when they might block.
Imminent takes advantage of this mechanism by implementing the ManagedBlocker
(see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ForkJoinPool...