Chapter 3 Multi Threading in java.pptx

desalewminale 14 views 36 slides May 29, 2024
Slide 1
Slide 1 of 36
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36

About This Presentation

multi treading pdf


Slide Content

Chapter 3

T hreads are a way to achieve concurrent execution of tasks, allowing different parts of a program to run independently. Threads are instances of the Thread class or objects that implement the Runnable interface. T hreads are a fundamental part of concurrent programming. A thread is the smallest unit of execution within a process. Java provides built-in support for multithreading through the Thread class and the java.util.concurrent package.

Whenever we create a thread in Java, it always has some priority assigned to it. Priority can either be given by JVM while creating the thread or it can be given by the programmer explicitly.  Thread with the highest priority will get an execution chance prior to other threads. Suppose there are 3 threads t1, t2, and t3 with priorities 4, 6, and 1. So, thread t2 will execute first based on maximum priority 6 after that t1 will execute and then t3. The default priority for the main thread is always 5, it can be changed later.

Creating Multiple Thread

S ynchronization in java is a concept that deals with the coordination of multiple threads to ensure that they access shared resources in a safe and orderly manner. In a multithreaded environment, where multiple threads are executing concurrently, synchronization becomes crucial to avoid data inconsistency and potential race conditions. Java synchronization