Ways to create Threads

There are two ways to create threads

  • Extending the Thread class

  • Implementing the Runnable interface

Extending the Thread Class

The following is the example of creation of a new thread by extending the Thread Class.

Implementing the Runnable interface

The following is the example of creation of a new thread by implements Runnable Interface.

The above example shows how to create and start a thread. But when we calls start method, which eventually invokes a native method of a thread class and native method gives us a new thread. This native method implementation may vary from one O/S to other.


<-PREV NEXT->