0% found this document useful (0 votes)
17 views

4-Multithreaded Programming-13Aug24

Uploaded by

22pw03
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

4-Multithreaded Programming-13Aug24

Uploaded by

22pw03
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Chapter - 4

MULTITHREADED
PROGRAMMING

1
Java Thread Model - Priorities -
Synchronization - Messaging - Thread class
and Runnable Interface - Main thread –
Creating threads - Synchronization –
Interthread Communication - Deadlock

(10)
Topics of today!!!
 What is Multitasking?
 Introduction about Multithreading
 Single Threaded Program
 Example of Multithreading
 Advantages of Multithreading
 Disadvantages of Multithreading
 Comparison
 Life Cycle of Thread
3
What is Multitasking?
 The running of two or more programs (sets of
instructions) in one computer at the same time
 Used to keep all of a computer's resources at
work as much of the time as possible
 Divided into two types
 Process-based – two or more programs runs
concurrently
 Thread-based – a single program can perform
two or more tasks simultaneously
4
Introduction about Multithreading
 Built in support for Multithreaded programming
 Thread is a part of the program
 A multithreaded program contains two or more
parts that can concurrently
 Each thread defines a separate path of execution
 Multithreading is a specialized form of
Multitasking

5
Single Threaded Program

6
Single Threaded Program (cont..)
 When we execute an application
1. The JVM creates a Thread object whose task
is defined by the main() method
2. The JVM starts the thread
3. The thread executes the statements of the
program one by one
4. After executing all the statements, the
method returns and the thread dies

7
Examples of Multithreading
 Word processor tool
 Video Games
 Web Servers
 File Processing
 Image Processing

8
Advantages of Multithreading
 Proper utilization or max utilization is possible
 Decreased cost of maintenance
 Time saving
 Improves the performance of complex
applications
 Parallelize tasks

9
Disadvantages of Multithreading
 Complex debugging and testing processes
 Increased difficulty level in writing a program
 Unpredictable results

10
Comparison

11
Life Cycle of Thread
 Life Cycle of Thread in Java is basically state transitions
of a thread that starts from its birth and ends on its
death
 Thread States - a path of execution in a program that
enters in any one of the following states
1. New – begins its life cycle in the new state
2. Runnable – waiting for availability of the processor
3. Running – processor gives time slot for execution
4. Blocked (Non-runnable state) – considered to
blocked
5. Dead – completes the execution
12
Life Cycle of Thread (cont..)

13
References
 https://www.tutorialspoint.com/java/java_multithreading.htm
 https://www.javatpoint.com/multithreading-in-java
 https://www.geeksforgeeks.org/multithreading-in-java/
 http://tutorials.jenkov.com/java-concurrency/index.html
 https://www.journaldev.com/1079/multithreading-in-java
 https://beginnersbook.com/2013/03/multithreading-in-java/

14

You might also like