0% found this document useful (0 votes)
16 views22 pages

Unit 2 Multithreading

The document discusses the types of threads in programming, including the main thread and child threads, and how their execution is managed by the JVM or programmer. It highlights the importance of synchronization to prevent conflicts when multiple threads access shared resources, emphasizing the need for thread communication methods like wait(), notify(), and notifyAll(). Overall, it outlines the mechanisms for managing thread execution and communication to ensure correct program behavior.

Uploaded by

Tanmay Vaij
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)
16 views22 pages

Unit 2 Multithreading

The document discusses the types of threads in programming, including the main thread and child threads, and how their execution is managed by the JVM or programmer. It highlights the importance of synchronization to prevent conflicts when multiple threads access shared resources, emphasizing the need for thread communication methods like wait(), notify(), and notifyAll(). Overall, it outlines the mechanisms for managing thread execution and communication to ensure correct program behavior.

Uploaded by

Tanmay Vaij
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/ 22

Types: Main Thread- contains main method, execution & termination of program is

done from main thread


Child Threads
(Process based & thread based)
Precedence given
by JVM or
programmer to
threads for
execution.

Describes how
early gets executed
& selected by
Thread Scheduler

ThreadName.getPriority();
Synchronizing Threads
Asynchronous execution: Threads executing concurrently. Might
generate incorrect result.
Suppose, One thread trying to read record from file and other thread is still
writing the same file. This creates conflicts and needs synchronization

Synchronization: Process of handling resource accessibility by


multiple thread requests.
Aim: To avoid thread interference.
At a time when more than one thread tries to access the same resource,
we need to ensure that resource will be used by only one thread at a time.
Internet-Communication of Threads
Inter-Thread communication is about allowing synchronized threads to
communicate with each other.
Mechanism in which thread is paused running in its critical section and
another thread is allowed to enter (or lock) in the same critical section.

It is implemented by following methods:


wait(): causes current thread to release the lock and wait until other
threads wakes it up or time has elapsed.

notify(): waking up a single thread that is waiting on this object’s monitor.

notifyA(): wakes up all threads waiting on this object’s monitor

You might also like