---
title: "difference between \"implements Runnable”  and “extends Thread”"  
description: "difference between \"implements Runnable”  and “extends Thread”"  
author: "Anonymous User"  
published: 2015-05-08  
updated: 2015-05-08  
canonical: https://www.mindstick.com/forum/23202/difference-between-implements-runnable-and-extends-thread  
category: "java"  
tags: ["java", "thread"]  
reading_time: 3 minutes  

---

# difference between "implements Runnable”  and “extends Thread”

From what time I've spent with [threads](https://www.mindstick.com/blog/11678/threads-in-java) in [Java](https://www.mindstick.com/articles/12214/web-development-company-in-india-laid-on-the-foundation-of-concrete-java-programming), I've found these two ways to write threads:\
With implements [Runnable](https://www.mindstick.com/forum/160962/what-is-the-difference-between-callable-and-runnable-in-java):\

```
public class ThreadA implements Runnable {    public void run() {        //Code    }}
```

//Started with a "new Thread(threadA).start()" callOr, with extends Thread:\

```
public class ThreadB extends Thread {    public ThreadB() {        super("ThreadB");    }    public void run() {        //Code    }}
```

//Started with a "threadB.start()" callIs there any significant [difference](https://www.mindstick.com/articles/157114/good-news-or-bad-news-and-the-difference-is) in these two blocks of [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) ?

## Replies

### Reply by Anonymous User

Yes: implements Runnable is the preferred way to do it, IMO. You're not really specialising the thread's behaviour. You're just giving it something to run. That means [composition](http://en.wikipedia.org/wiki/Object_composition) is the philosophically "purer" way to go.\
In *practical* terms, it means you can implement **Runnable** and extend from another class as well. Java only supports single inheritance, so you can only extend one class. \
In general, I would recommend using something like Runnable rather than Thread because it allows you to keep your work only loosely coupled with your choice of concurrency. For example, if you use a Runnable and decide later on that this doesn't in fact require it's own Thread, you can just call threadA.run().\
**Caveat:** Around here, I strongly discourage the use of raw Threads. I much prefer the use of Callables and FutureTasks (From the javadoc: "A cancellable asynchronous computation"). The integration of timeouts, proper cancelling and the thread pooling of the modern concurrency support are all much more useful to me than piles of raw Threads.\
**Follow-up:** there is a *FutureTask* constructor that allows you to use Runnables (if that's what you are most comfortable with) and still get the benefit of the modern concurrency tools. To quote the javadoc:\
If you don't need a particular result, consider using constructions of the form:\

```
Future<?> f = new FutureTask<Object>(runnable, null)
```

So, if we replace their runnable with your threadA, we get the following:\

```
new FutureTask<Object>(threadA, null)
```

Another option that allows you to stay closer to Runnables is a *ThreadPoolExecutor*. You can use the execute method to pass in a Runnable to execute "the given task sometime in the future."\
If you'd like to try using a thread pool, the code fragment above would become something like the following (using the **Executors.newCachedThreadPool()** factory method):\

```
ExecutorService es = Executors.newCachedThreadPool();es.execute(new ThreadA());                                                                       
```


---

Original Source: https://www.mindstick.com/forum/23202/difference-between-implements-runnable-and-extends-thread

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
