I faced a problem about ThreadPoolExecutor.
After writing some code, I found the submit() method will eat the RuntimeException thrown by the program, but the execute() method will re-throw the RuntimeException`. I want to know the reason for this.
I recently read the source code of ThreadPoolExecutor and know the principle of a thread pool.
Now I understand how execute() method executes, but I couldn't understand how submit() method executes. I only know that the submit() method will wrap the Runnable or Callable in a FutureTask and call the execute() method:
public Future submit(Runnable runnable)
{
if(runnable == null)
{
throw new NullPointerException();
} else
{
RunnableFuture runnablefuture = newTaskFor(runnable, null);
execute(runnablefuture);
return runnablefuture;
}
}
So, my problem is: how does ThreadPoolExecutor execute FutureTask and why is the RuntimeException eaten?