The Executor Interface
Home ] Up ] [ The Executor Interface ] The ExecutorService Interface ] ScheduledExecutorService ] The Executors Class ] Example ]

 

 

A class that implements the Executor interface is an object that executes submitted Runnable tasks. This interface provides a way of decoupling task submission from the mechanics of how each task will be run, including details of thread use, scheduling, etc.

An Executor object is designed to replace the standard approach to starting a thread with its own style.  If r is a Runnable object, and e is an Executor object you can replace

(new Thread(r)).start();
with
e.execute(r);

Here is the single method that the Executor interface specifies:

void execute(Runnable command)
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.
Parameters:
command - the runnable task
Throws:
RejectedExecutionException - if this task cannot be accepted for execution.
NullPointerException - if command is null
 
The page was last updated February 19, 2008