0% found this document useful (0 votes)
6 views5 pages

How To Create Threads and Thread Life Cycle in Java by Deepak Smart Programming Lyst4980

The document provides a guide on creating threads in Java using the Runnable interface, detailing the steps involved in the process. It outlines the life cycle of a thread, including the stages of Born, Runnable, Running, Non-Runnable, and Dead. Additionally, it notes that a thread can only be started once, or an IllegalThreadStateException will occur.

Uploaded by

Aakash Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

How To Create Threads and Thread Life Cycle in Java by Deepak Smart Programming Lyst4980

The document provides a guide on creating threads in Java using the Runnable interface, detailing the steps involved in the process. It outlines the life cycle of a thread, including the stages of Born, Runnable, Running, Non-Runnable, and Dead. Additionally, it notes that a thread can only be started once, or an IllegalThreadStateException will occur.

Uploaded by

Aakash Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Smart Programming : Channel

An investment in Knowledge pays the best interest….

Creating Threads (Part 2)


in Java
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308

=> By using "Runnable" interface :-


 Steps to create thread using "Runnable"
interface :-
1. inherits the "Runnable" interface
2. override the run() method
3. create an instance of the class
4. create an instance of Thread class and pass the
above class instance in thread class constructor
5. start the thread

=> Life cycle of thread :-


1. Born : New thread is created.
MyThread mt=new MyThread();
mt.start();

2. Runnable : In this stage thread comes in ready


stage

1
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308

3. Running : In this stage thread starts its task i.e.


run() method is executing

4. Non-Runnable : In this stage thread does not


perform any task. But when the thread is
invoked then thread goes to the runnable stage
and then it goes to the running stage

5. Dead : In this stage thread completes its task


and removed from the memory

2
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308

=> Note :
 We can envoke (start) the thread only once. If
we try to start the thread again it will provide an
exception saying
java.lang.IllegalThreadStateException

3
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308

Company Links & Contacts

Company Name: Smart Programming (+91 62838-30308)

Address : Chandigarh & Mohali (Punjab), India

Websites: https://www.smartprogramming.in/
https://courses.smartprogramming.in

Android App:
https://play.google.com/store/apps/details?id=com.sma
rtprogramming

YouTube Channel:
https://www.youtube.com/c/SmartProgramming

You might also like