Friday 8 July 2016

Executor.execute() vs ExecutorService.submit()

1) Both submit() and execute() methods are used to submit a task to Executor framework for asynchronous execution.

2) Both submit() and execute() can accept a Runnable task.

3) You can access submit() and execute() from the ExecutorService interface because it also extends the Executor interface which declares the execute() method.

Apart from the fact that submit() method can return output and execute() cannot, following are other notable differences between these two key methods of Executor framework of Java 5.

1) The submit() can accept both Runnable and Callable task but execute() can only accept the Runnable task.

2) The submit() method is declared in ExecutorService interface while execute() method is declared in the Executor interface.

3) The return type of submit() method is a Future object but return type of execute() method is void.

Read more: http://javarevisited.blogspot.com/2016/04/difference-between-ExecutorServie-submit-vs-Executor-execute-method-in-Java.html#ixzz4DooQVq5V

No comments:

Post a Comment