Example & Tutorial understanding programming in easy ways.

Difference between submit() and execute() method thread pool in Java?

Both method are ways to submit task to thread pools but there is slight difference
between them.

execute(Runnable command) is defined in Executor interface and
executes given task in future, but more importantly it does not return anything. It's
return type is void.

On other hand submit() is overloaded method, it can take
either Runnable or Callable task and can return Future object which can hold
pending result of computation.

This method is defined
on ExecutorService interface, which extends Executor interface, and every
other thread pool class
e.g. ThreadPoolExecutor or ScheduledThreadPoolExecutor gets these

Read More →