The document explains the differences between Executor.submit() and Executor.execute() methods, highlighting that exceptions thrown by tasks submitted with execute go to the uncaught exception handler, while those submitted with submit are part of the task's return status and can be re-thrown via Future.get. It also discusses the distinction between factory and abstract factory patterns, noting that the abstract factory provides an additional level of abstraction with different factories responsible for creating various object hierarchies. Examples of such factories include AutomobileFactory, UserFactory, and RoleFactory.
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
0 views
CoreJavaQuestions
The document explains the differences between Executor.submit() and Executor.execute() methods, highlighting that exceptions thrown by tasks submitted with execute go to the uncaught exception handler, while those submitted with submit are part of the task's return status and can be re-thrown via Future.get. It also discusses the distinction between factory and abstract factory patterns, noting that the abstract factory provides an additional level of abstraction with different factories responsible for creating various object hierarchies. Examples of such factories include AutomobileFactory, UserFactory, and RoleFactory.
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1
Q) What is difference between Executor.submit() and Executer.execute() method ?
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.
Q) What is the difference between factory and abstract factory pattern?
Abstract Factory provides one more level of abstraction. Consider different factories each extended from an Abstract Factory and responsible for creation of different hierarchies of objects based on the type of factory. E.g. AbstractFactory extended by AutomobileFactory, UserFactory, RoleFactory etc. Each individual factory would be responsible for creation of objects in that genre.