Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Callable : What happens to the thread before get() is called

More precisely : If I start async computation by calling submit(Callable<T> task) method on an ExecutorService (itself constructed with Executors.newCachedThreadPool()), I can wait for the computation to finish and retrieve the result by calling Future.get().

My question is : if the computation is already finished, what happens until I call get()? Does the thread is blocked until I retrieved the result? Does the result is stored and the thread assigned to another task? Something completely different?

Thanks in advance for you answers

like image 407
shadow_heart Avatar asked Sep 28 '22 10:09

shadow_heart


1 Answers

No, Thread is not blocked, it is returned to the pool. In general it is the get() calling thread dependant on worker, not the other way around. So if there is a result, return it, if not, wait until it will be available.

like image 193
Antoniossss Avatar answered Nov 02 '22 05:11

Antoniossss