I am trying to understand the working of FutureTask
in Collections
. From what I read I understand you can create a thread pool using ExecutorService
. Later you can wrap Runnable
or Callable
in FutureTask
and execute it. After that you can use the Future object to check get the results or check if task is running. But how does this do internally ?
What I am trying to understand is what happens behind the scene when you pass a Callable interface. Few questions I have are
Does the FutureTask itself runs a thread internally to constantly check if the Callable command has finished execution ? If not then how does it know when the command is finished execution?
How does the get() method work? How does it get the value that is returned from the Callable interface ?
Looking at the documentation I couldn't figure out much. Is there any code example that I can look at to understand the behind the scenes.