Differences between execute() and submit() method of executor framework in java





Before this tutorial please read : Executor framework in java.



There are following differences between execute() and submit() method of Executor framework in java >



execute() method in java
submit() method in java
execute() method is defined in Executor interface.
submit() method is defined in ExecutorService interface.
It can be used for executing runnable task.
It can be used for executing runnable  task or callable task, submitted callable returns future and Future's get method will return the task's result.
Signature of execute method is  >
void execute(Runnable task)
submit method has 3 forms >
<T> Future<T> submit(Callable<T> task)
Submits a callable task for execution.
Method returns a Future which represents pending results of the task.
Once task is completed Future's get method will return the task's result.

<T> Future<T> submit(Runnable task, T result)
Submits a Runnable task for execution.
Method returns a Future which represents that task. Once task is completed Future's get method will return result.

Future<?> submit(Runnable task)
Submits a Runnable task for execution.
Method returns a Future which represents that task. Once task is completed Future's get method will return null.

So, in this thread concurrency tutorial we read differences between execute() and submit() method of Executor framework in java.

Having any doubt? or you you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.


/** Copyright (c), AnkitMittal JavaMadeSoEasy.com */

RELATED LINKS>

Important Similarity and Differences >

Differences between execute() and submit() method of executor framework

Difference between synchronized and ReentrantLock

Similarity and Difference between CyclicBarrier and CountDownLatch in Java



Thread concurrency Interviews >

eEdit
Must read for you :