Wednesday 20 August 2014

What is difference between Executor.submit() and Executer.execute() method ?

The answer is that former returns an object of Future which can be used to find result from worker thread)

There is a difference when looking at exception handling. If your tasks throws an exception and if it was submitted with execute this exception will go to the uncaught exception handler (when you don't have provided one explicitly, the default one will just print the stack trace to System.err). If you submitted the task with submit any thrown exception, checked exception or not, is then part of the task's return status. For a task that was submitted with submit and that terminates with an exception, the Future.get will re-throw this exception, wrapped in an ExecutionException.

2 comments:

  1. the answer given here seems like a copy paste from one of the popular site for java interview question!!!
    I was looking for a detailed description!

    ReplyDelete
  2. Hi To know more about java interview question! With answer. Visit here https://technofaq.org/posts/2017/07/top-10-interview-questions-answers-for-java-developers/

    ReplyDelete