Executer and ExcuterService:
Executor and ExecutorService are part of Java's Executor framework, which provides thread pool facilities to Java applications. Since creating and managing Threads are expensive, It's a better idea to create a thread pool that can execute in parallel rather than every time a new thread is requested, helping reduce the load. This improves the response time of the application.
Differences between Executer and ExecuterService:
- One of the key differences between the Executor and ExecutorService interface is that the former is a parent interface while ExecutorService extends Executor.
- A second significant difference between ExecutorService and Executor is that Executor defines an execute() method, which accepts the Runnable interface object. Simultaneously, a submit() method takes both Runnable and Callable object interfaces.
- Another difference between Executor and ExecutorService interface is that the execute() methods' return type is void, whereas the submit() method returns a Future object, which is the fundamental difference between the submit() and execute() method.
- The fourth difference between ExecutorService and Executor interface is that apart from allowing a client to submit a task, ExecutorService also provides methods to control the thread pool, e.g. terminate the thread pool by calling the shutDown() method.