I'm using Java 8. I was wondering how you can tell when a Future object is done with its task. I tried understanding it by writing the below
Callable<Long> c = new Callable<Long>() {
@Override
public Long call() throws Exception {
return new Long(factorial(1));
}
};
ExecutorService s = Executors.newFixedThreadPool(2);
Future<Long> f = s.submit(c);
while (!f.isDone())
{
System.out.println("waiting..." + f.get().toString());
} // while
System.out.println(f.get().toString());
but the while loop never returns (f.isDone() is always false) even though I can tell there is a computed result.