Create Thread in Java | Core Java Tutorials

This “Create Thread in Java” explains clearly that how to create thread in java application either by extending from Thread class or by using Runnable interface belongs to lang package.


Creating a Thread:

  • java.lang package providing pre-defined class and interface to create User threads.
  • A thread can be created in 2 ways…
    1. By extending from java.lang.Thread class
    2. By implementing from java.lang.Runnable interface
  • Every Thread class must override “public void run() ” method in it’s definition.
  • run() method contains the logic that executes in parallel.
  • Pre-defined run() method is having empty definition.

Thread Creation in 2 ways in java


When we use Runnable interface?

  • Thread can be created in 2 ways.
  • It is easy to create thread by extending from Thread class.
  • We can apply thread behavior to class easily by extending from Thread.
  • But if we want to apply thread behavior to Child in “Is-A relation”, we use Runnable interface.

Thread creation using Runnable interface


Share this