ExecutorService has two methods:

void execute(Runnable command) and

Future<?> submit(Runnable task) .

What is the difference between them in the behavior of threads, except for the return value?

    1 answer 1

    In the ForkJoinPool , ThreadPoolExecutor, and AbstractExecutorService classes, the submit uses execute . In the class ScheduledThreadPoolExecutor, submit and execute use the overloaded method schedule . So there is no difference.

    execute is a method from the Executor interface

    submit is a method from the ExecutorService interface that extends Executor .

    Since submit returns a value, it prepares the return value.

    • If submit is a wrapper over execute, does it do something? Otherwise, why is it even needed? - Pavel