[go: up one dir, main page]

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

4.1 Java

The document provides an overview of multithreading in Java, explaining its definition, advantages, and the concept of multitasking. It distinguishes between process-based and thread-based multitasking, highlighting the lightweight nature of threads and their independence. Additionally, it outlines the life cycle of a thread in Java, detailing the various states a thread can be in during its execution.

Uploaded by

sneha chaudhari
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)
6 views11 pages

4.1 Java

The document provides an overview of multithreading in Java, explaining its definition, advantages, and the concept of multitasking. It distinguishes between process-based and thread-based multitasking, highlighting the lightweight nature of threads and their independence. Additionally, it outlines the life cycle of a thread in Java, detailing the various states a thread can be in during its execution.

Uploaded by

sneha chaudhari
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/ 11

Java Programming

Sneha D. Patil
(Assistant Professor)
E&C department
INDEX
 INTRODUCTION TO MULTITHREADING
 ADVANTAGES
 MULTITASKING
 TYPES OF MULTI TASKING
 WHAT IS THREAD
 Life Cycle of a Thread in Java Multithreading
INTRODUCTION TO
MULTITHREADING
 Multithreading in Java is a process of
executing multiple threads simultaneously.
 A thread is a lightweight sub-process, the

smallest unit of processing. Multiprocessing


and multithreading, both are used to
achieve multitasking.
Advantages of Java Multithreading

1) It doesn't block the user because


threads are independent and you can
perform multiple operations at the same
time.
2) You can perform many operations
together, so it saves time.
3) Threads are independent, so it doesn't
affect other threads if an exception occurs
in a single thread.
Multitasking

 Multitasking is a process of executing


multiple tasks simultaneously. We use
multitasking to utilize the CPU. Multitasking
can be achieved in two ways:
 Process-based Multitasking

(Multiprocessing)
 Thread-based Multitasking (Multithreading)
Process-based Multitasking
(Multiprocessing)

 Each process has an address in memory. In


other words, each process allocates a
separate memory area.
 A process is heavyweight.
 Cost of communication between the process

is high.
 Switching from one process to another

requires some time for saving and loading


registers, memory maps, updating lists, etc.
Thread-based Multitasking
(Multithreading)
 Threads share the same address space.
 A thread is lightweight.
 Cost of communication between the thread

is low.
What is Thread in java

 A thread is a
lightweight subprocess,
the smallest unit of
processing. It is a
separate path of
execution.
 Threads are
independent. If there
occurs exception in one
thread, it doesn't affect
other threads. It uses a
shared memory area.
Life Cycle of a Thread in Java Multithreading
STAGES OF LIFECYCLE
 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.
 Terminated (Dead) − A runnable thread enters the terminated
state when it completes its task or otherwise terminates.
TO BE CONTINUE…..

You might also like