androidengineers.Book a session
โ† All interview questions
ThreadBeginner3 min

Difference between Thread and Runnable?

Answer

Thread vs Runnable

Both are ways to define work that runs on a separate thread, but they differ in design and flexibility.

Thread (Extending the Class)

class MyThread : Thread() {
    override fun run() {
        println("Running on: ${currentThread().name}")
    }
}

// Usage
val thread = MyThread()
thread.start()

Runnable (Implementing the Interface)

class MyRunnable : Runnable {
    override fun run() {
        println("Running on: ${Thread.currentThread().name}")
    }
}

// Usage
val thread = Thread(MyRunnable())
thread.start()

// Or with lambda
Thread { println("Lambda runnable") }.start()

Key Differences

AspectThreadRunnable
TypeClass (extends)Interface (implements)
InheritanceCan't extend another classCan extend another class
ReusabilityLess reusableMore reusable
Resource sharingEach thread = separate objectSame Runnable, multiple threads
Thread pool compatibleNoYes (Executor.execute(runnable))

Why Runnable is Preferred

1. Better OOP Design

class MyActivity : Activity(), Runnable {
    // Can implement Runnable AND extend Activity
    override fun run() { /* background work */ }
}

2. Separation of Concerns

  • Runnable = What to do (task)
  • Thread = How to run it (execution)

3. Thread Pool Compatibility

val runnable = Runnable { /* work */ }
executorService.execute(runnable)  // Works!
executorService.execute(thread)    // Doesn't make sense

4. Resource Efficiency

val task = Runnable { /* work */ }
// Reuse same task logic with multiple threads
repeat(5) { Thread(task).start() }

Modern Alternative: Callable

interface Callable<V> {
    fun call(): V  // Can return a result and throw exceptions
}

val callable = Callable { "Result" }
val future = executor.submit(callable)
val result = future.get()  // "Result"

Best Practice

In modern Android development:

  • Use Runnable for simple tasks
  • Use Callable when you need results
  • Prefer Coroutines for async work (most recommended)

Mark this when you can explain the answer in your own words.

Share & Help Others

Help fellow developers prepare for interviews

Sharing helps the Android community grow ๐Ÿ’š

Keep practising