Using a Future
like this:
public class Foo implements Future<Object>{
boolean done=false;
public boolean isDone(){
return done;
}
public Object get(){
done = true;
return "hi";
}
}
is get()
called twice anyhow?
Using a Future
like this:
public class Foo implements Future<Object>{
boolean done=false;
public boolean isDone(){
return done;
}
public Object get(){
done = true;
return "hi";
}
}
is get()
called twice anyhow?
It is quite possible (and in a multithreaded environment quite common) for get
to be called many times by many threads.
If you wish to implement Future<V>
you must implement the complete contract - including:
Future... The result can only be retrieved using method
get
when the computation has completed, blocking if necessary until it is ready.
You must therefore ensure that a call to get
blocks until the task is complete and then deliver the result of the task.