H Paul wrote:Now thread-wise:
Suppose there is a service (local or remote) that return a Response (any Object)
Future<Response> futureResponse = service.getResponse();
Implicitly there is a new worker thread to take care of the request freeing the calling thread to do some thing else.
Is this correct? Or correct/explain.
Possibly. Often it's not a
new thread, but one from a pre-existing thread pool. Or it might be that most of the real work is taking place on another machine entirely, elsewhere on the network. Or the thing we're waiting for might not be on a machine at all - it might be something that needs human input. There's probably a thread somewhere waiting for it - but it might even be a single thread waiting for a response to any of hundreds of requests out to other machines. So it's not necessarily one new thread per Future. The nice thing is, we don't really need to know what other threads are involved. The Future interface lets us ignore that and just find out if the result is there yet, or not.