Skip to content
Related Articles

Related Articles

Java.util.concurrent.Executor interface with Examples
  • Last Updated : 17 Jun, 2019

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.

Class heirarchy:

  ↳ Interface Executor

Implementing Sub-Interfaces:


Implementing Classes:


Methods in Executor interface:

  1. 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.

import java.util.concurrent.Executor;
import java.util.concurrent.RejectedExecutionException;
public class ExecutorDemo {
    public static void main(String[] args)
        ExecutorImp obj = new ExecutorImp();
        try {
            obj.execute(new NewThread());
        catch (RejectedExecutionException
               | NullPointerException exception) {
class ExecutorImp implements Executor {
    public void execute(Runnable command)
        new Thread(command).start();
class NewThread implements Runnable {
    public void run()
        System.out.println("Thread executed under an executor");
Thread executed under an executor


Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :