/** * This method enables blocking Suppliers to be used efficiently * with the common Java fork/join thread pool. */ public static<T> T callInManagedBlock(final Supplier<T> supplier) { // Create a helper object to encapsulate the supplier. final SupplierManagedBlocker<T> managedBlock = new SupplierManagedBlocker<>(supplier); try { /* // Submit managedBlock to the common ForkJoin thread pool. System.out.println(TAG + "calling managedBlock() in thread " + Thread.currentThread()); */ ForkJoinPool.managedBlock(managedBlock); } catch (InterruptedException e) { throw new Error(e); } // Return the results. return managedBlock.getResult(); }