The concurrent API in Java provides a feature known as an executor that initiates and controls the execution of threads. As such, an executor offers an alternative to managing threads using the thread class. At the core of an executor is the Executor interface. It refers to the objects that execute submitted Runnable tasks.
java.util.concurrent ↳ Interface Executor
AbstractExecutorService ForkJoinPool ScheduledThreadPoolExecutor ThreadPoolExecutor
Methods in Executor interface:
- execute(): This function executes the given command at some time in the future. The command may execute in a new thread, in a pooled thread, or in the calling thread, at the discretion of the Executor implementation.
void execute(Runnable task)
Example to demonstrate an Executor.
Thread executed under an executor
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Java.util.BitSet class methods in Java with Examples | Set 2
- Comparator Interface in Java with Examples
- Nested Interface in Java
- Java Interface methods
- Queue Interface In Java
- Date class in Java (With Examples)
- List Interface in Java with Examples
- Arrays.sort() in Java with examples
- Arrays.fill() in Java with Examples
- LinkedHashSet in Java with Examples
- SortedSet Interface in Java with Examples
- Split() String method in Java with examples
- Map Interface in Java
- SortedMap Interface in Java with Examples
- NavigableSet in Java with Examples
- NavigableMap Interface in Java with Example
- Collections.sort() in Java with Examples
- Collections.binarySearch() in Java with Examples
- Deque interface in Java with Example
- Collections.reverse() in Java with Examples