Difference between Thread and Runnable in Java

UPDATED: 01 August 2016
extends Thread vs implements Runnable

Inheritance
Java supports only single Inheritance means you can't extend more than one class. When you extends Thread you lose the opportunity to extend another class.

Implementing Runnable interface gives you window to extend another class.

Extending class
Extending class means you are changing behavior of super class with your implementation. Since you are not changing the behavior of Thread, implement Runnable.

Runnable as Task
Implementing Runnable represents standalone Task and can be executed by simple Thread or Executors.

Runnable means we can reuse the Task, but you can't restart the Thread once it completes.

Executor Interface
Since you can't restart the Thread once it completes, Java designer decided to accept Runnable class in Executor Interface and it gives more control over your Task compare to Thread.

0 comments :