What is the difference between ExecutorService.submit and ExecutorService.execute in this code in Java?

As you see from the JavaDoc execute(Runnable) does not return anything.

However, submit(Callable<T>) returns a Future object which allows a way for you to programatically cancel the running thread later as well as get the T that is returned when the Callable completes. See JavaDoc of Future for more details

Future<?> future = executor.submit(longRunningJob);
...
//long running job is taking too long
future.cancel(true);

Moreover,
if future.get() == null and doesn’t throw any exception then Runnable executed successfully

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)