Multithreading in Java by Inheriting Thread Class

Multithreading is a Java feature that allows concurrent execution of two or more parts of a program for maximum utilization of CPU. Each part of such program is called a thread. So, threads are light-weight processes within a process.

As discussed in the previous post Threads can be created by using two mechanisms :
1. Extending the Thread class
2. Implementing the Runnable Interface

In this post we will understand the first method by performing multi threading using Thread Class(inheriting the Thread Class)

Output –

Thread Class vs Runnable Interface

1. If we extend the Thread class, our class cannot extend any other class because Java doesn’t support multiple inheritance. But, if we implement the Runnable interface, our class can still extend other base classes.

2. We can achieve basic functionality of a thread by extending Thread class because it provides some inbuilt methods like yield(), interrupt() etc. that are not available in Runnable interface.

Leave a Reply

Your email address will not be published. Required fields are marked *