
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Difference between Executor and ExecutorServices in Java
Executor and ExecutorServices both interfaces are part of the Executor framework. It is released with Java 5.
In java, thread creation is very expensive operation so we should reuse the available thread instead of starting a new thread every time and we can achieve the same using Executor framework.
Executor framework use the thread pool to execute the task parallel which helps to optimize response time and resource utilization. It provides four types of built in thread pools −
- Fixed Thread Pool
- Cached Thread Pool
- Scheduled Thread Pool
- Single Thread Executor
Sr. No. | Key | Executor | ExecutorServices |
---|---|---|---|
1 | Basic | It is a parent interface | It extends Executor Interface |
2 | Method | It has execute() method | It has submit() method |
3 | Return Type | It does not return anything . | It return future object. |
4. | Runnable /Callable | It accept runnable object. | It accept both runnable and callable |
Example of ExecutorService
public class Main { public static void main(String args[]) { ExecutorService services = Executors.newSingleThreadExecutor(); Future<?> future = services.submit(new Task()); } } public class Task implements Runnable { @Override public void run() { System.out.println("In Run"); } }
Example of Executor
public class Main { public static void main(String args[]) { Executor executor = Executors.newSingleThreadExecutor(); executor.execute(new Task()); } } public class Task implements Runnable { @Override public void run() { System.out.println("In Run"); } }
- Related Articles
- Difference between scheduledThread pool and Single Thread Executor.
- Difference between Java and JavaScript.
- Difference between Go and Java.
- Difference Between C++ and Java
- Difference between Groovy and Java
- Difference between constructor and method in Java
- Difference between Object and Class in Java
- Difference between HashMap and HashTable in Java.
- Difference between StringBuilder and StringBuffer in Java
- Difference between string and StringBuffer in Java.
- Difference between == and equals() method in Java.
- Difference between charAt() and indexOf() in Java ?
- Difference between ArrayList and CopyOnWriteArrayList in Java
- Difference between HashMap and ConcurrentHashMap in Java
- Difference between HashTable and HashMap in Java

Advertisements