🚀 Enrollments Open for Jetpack Compose Cohort 3 — 4 Weeks of Live Learning to Build Modern Android UIs 💚Join Now
ThreadBeginner3 min
Difference between Thread and Runnable?
ThreadRunnable

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)

Want to master these concepts?

Join our live cohorts and build production-ready Android apps.

1:1 Mentorship

Get personalized guidance from a Google Developer Expert. Accelerate your career with dedicated support.

Personalized Learning Path
Mock Interviews & Feedback
Resume & Career Guidance

Limited slots available each month