multithreading

Thread vs Runnable? Which is better?

Extending Thread:

  • Limited by single inheritance (you cannot extend another class).

Implementing Runnable:

  • Better: Leaves your class free to extend another class.
  • Supports better separation of task (the code in run()) and worker (the Thread instance).
  • Ideal for use with ExecutorService.

Runnable as Lambda:

Thread t = new Thread(() -> System.out.println("Running...")); t.start();
Thread vs Runnable? Which is better? | DevExCode