by Dinesh Thakur

Thread is a lightweight process. It is lightweight because they utilize the minimum resources of the system. Thread is an independent concurrent path of execution of a group of statements. Thread takes less memory and less process time.

Threading is a technique to allow multiple activities to execute simultaneously within the single process.

Types of Thread

1. Daemon Thread or System defined Thread e.g-Garbage collector user defined Thread

How to create user defined thread. Programmer creates user defined thread in two ways. By implementing Runnable interface

1st- the class must implement the Runnable interface, construct the object of the class and this object is treated as Runnable object.

2nd- construct the Thread class object by passing runable object as an argument

3rd- call the start method of Thread class to execute the thread and make the thread eligible to run.

4th- Programmer bound override the run method of the Runnable interface to move thread into running state. start method implicitly call run method.

By extending Thread class

1st- the class must extends the Thread class and must override the run method Thread class.

2nd- Within the child class constructor, programmer is bound to explicitly call the base class parameterized constructor (by using super keyword), otherwise child class constructor implicitly call base class default constructor.

3rd- call the start method of Thread class to make thread eligible to run.

4th- Start method implicitly calls the override rum method.