Java Concurrency Interview

Threads and lifecycle question 6 of 180 junior

What is the difference between Runnable and Callable, and where does Future fit?

Runnable.run() returns void and cannot throw checked exceptions, so a failure inside it has nowhere to go except the thread's uncaught exception handler. Callable.call() returns V and may throw, which is what lets an executor capture the outcome.

submit wraps either into a Future. Calling get() blocks until the task finishes and then either returns the value or throws ExecutionException with the original failure as its cause. That is the important half: with execute(Runnable) an exception is printed and lost, with submit it is stored in the Future and is lost only if nobody ever calls get().

basics executors

Quiz yourself on Threads and lifecycle Suggest a correction