Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's the difference between Executor and ExecutorService? [closed]

Tags:

java

I am wondering what's the difference between Executor and ExecutorService?

Any example will help.

like image 712
Adam Lee Avatar asked Feb 24 '13 13:02

Adam Lee


People also ask

What does ExecutorService shutdown do?

Two different methods are provided for shutting down an ExecutorService. The shutdown() method will allow previously submitted tasks to execute before terminating, while the shutdownNow() method prevents waiting tasks from starting and attempts to stop currently executing tasks.

Is it necessary to shutdown ExecutorService?

When finished using an ExecutorService , you need to shut it down explicitly. From its javadoc: "An unused ExecutorService should be shut down to allow reclamation of its resources." Calling shutdown initiates a gradual and orderly shutdown.

What is the difference between the submit () and execute () method of executor and ExecutorService in Java?

1) The submit() can accept both Runnable and Callable tasks but execute() can only accept the Runnable task. 2) The submit() method is declared in the ExecutorService interface while the execute() method is declared in the Executor interface.

What is an ExecutorService?

ExecutorService is a JDK API that simplifies running tasks in asynchronous mode. Generally speaking, ExecutorService automatically provides a pool of threads and an API for assigning tasks to it.


1 Answers

Executor just executes stuff you give it.

ExecutorService adds startup, shutdown, and the ability to wait for and look at the status of jobs you've submitted for execution on top of Executor (which it extends).

like image 88
radai Avatar answered Oct 09 '22 01:10

radai