0% found this document useful (0 votes)
3 views15 pages

Institute: Uie Department: Cse: Bachelor of Engineering (Computer Science & Engineering)

The document presents an overview of multithreading in Java, explaining its advantages, issues, and the life cycle of a thread. It highlights the differences between multitasking and multithreading, emphasizing that threads are lightweight processes that share the same address space. The session concludes with a summary of key learning points and references for further study.

Uploaded by

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

Institute: Uie Department: Cse: Bachelor of Engineering (Computer Science & Engineering)

The document presents an overview of multithreading in Java, explaining its advantages, issues, and the life cycle of a thread. It highlights the differences between multitasking and multithreading, emphasizing that threads are lightweight processes that share the same address space. The session concludes with a summary of key learning points and references for further study.

Uploaded by

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

INSTITUTE : UIE

DEPARTMENT : CSE
Bachelor of Engineering (Computer Science &
Engineering)

Object Oriented Programming using Java


(23CSP-202 )
TOPIC OF PRESENTATION:
Introduction to Multithreading, Thread Life cycle. Prepared by:
Multi threading advantages and issues. Bhavneet Kaur
Master Subject
Coordinator
DISCOVER . LEARN . EMPOWER
Lecture Objectives

In this lecture, we will discuss:


•Introduction to
Multithreading, Thread Life
cycle.
•Multi threading advantages
and issues.

2
Multithreading
Java's multithreading functionality
enables two or more application
components to
run concurrently for optimal CPU
utilization.

A thread is the name given to each


component of such a program.
Threads are hence lightweight
processes inside other processes.
Multitasking Vs. Multithreading

Compared to multithreading, multitasking is characterized by the following:

• Each process requires its own separate address space

• Context switching from one process to another is a CPU intensive task needing more time.

• Inter-process communication between processes is again expensive as the communication


mechanism has to span separate address spaces

These are the reasons why processes are referred to as heavyweight tasks
Multitasking Vs. Multithreading (cont...)

Threads cost less in terms of processor overhead because of the following


reasons:

– Multiple threads in a program share the same address space and they are
part of the same process

– Switching from one thread to another is less CPU intensive

– Inter-thread communication, on the other hand, is less expensive as threads


in a program communicate within the same address space

• Threads are therefore called lightweight processes


Use of
Multithreading

It is
accomplished
by having each
activity
performed by a
separate thread Threads are the
A multithreaded
application lightest tasks within a
performs two or program, and they
more activities share memory space
concurrently and resources with
each other
QUIZ

Choose Correct option which defines the multithreaded


programming

1.It is a process in which a single process can access


information from many sources
2.It is a process in which many different process are able
to access same information
3.It is a process in which two different processes run
simultaneously
4.It is a process in which two or more parts of same
process run simultaneously
Life Cycle of a Thread
A thread goes through various stages in its life cycle. For example,
a thread is born, started, runs, and then dies. The following
diagram shows the complete life cycle of a thread.
Following are the stages of the life cycle −

New − A new thread begins its life cycle in the new state. It
remains in this state until the program starts the thread. It is also
referred to as a born thread.
Runnable − After a newly born thread is started, the thread
becomes runnable. A thread in this state is considered to be
executing its task.
Waiting − Sometimes, a thread transitions to the waiting
state while the thread waits for another thread to perform a
task. A thread transitions back to the runnable state only when
another thread signals the waiting thread to continue executing.
Timed Waiting − A runnable thread can enter the timed
waiting state for a specified interval of time. A thread in
this state transitions back to the runnable state when that time
interval expires or when the event it is waiting for occurs.
Advantages of a Multithreaded Application

•Improved performance and concurrency


•Simplified coding of remote procedure calls and
conversations
•Simultaneous access to multiple applications
•Reduced number of required servers
Disadvantages of a Multithreaded Application

Multithreaded applications present the following disadvantages:

•Difficulty of writing code


•Difficulty of debugging
•Difficulty of managing concurrency
•Difficulty of testing
•Difficulty of porting existing code
QUIZ:

A process can be ___________


a) single threaded
b) multithreaded
c) both single threaded and multithreaded
d) none of the mentioned

Termination of the process terminates ___________


a) first thread of the process
b) first two threads of the process
c) all threads within the process
d) no thread within the process
Summary:

In this session, you were able to :

•Learn about Multithreading


•Understand Thread Life cycle
•Learn about Multi threading advantages and issues.
References
Books:
1. Balaguruswamy, Java.
2. A Primer, E.Balaguruswamy, Programming with Java, Tata McGraw
Hill Companies
3. John P. Flynt Thomson, Java Programming.
4. Java Concurrency in Practice

Video Links:
https://youtu.be/O_Ojfq-OIpM
https://youtu.be/JceAHRlQsqc

Reference Links:
https://www.geeksforgeeks.org/lifecycle-and-states-of-a-thread-in-java/
https://www.journaldev.com/1044/thread-life-cycle-in-java-thread-state
s-in-java
https://www.iitk.ac.in/esc101/05Aug/tutorial/essential/threads/lifecycle.
html
https://www.decodejava.com/life-cycle-of-thread.htm
THANK YOU

You might also like