-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotes_multithreadingInJava
More file actions
40 lines (24 loc) · 1.6 KB
/
Notes_multithreadingInJava
File metadata and controls
40 lines (24 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Thread
-------
start()-- helps the thread to start.
run()- internally calls theis method to go further to initate the task;
joint()-- waits until the thread is fineshed or terminated.
sleep() -- used to apply temporery hold on the thread and release once the time is up.
--> if any interuption occurs it will lead to interupatedExcption occurs
eg : notification service example were we give pause for every notification sent to the end user.
wait() -- thread is put hold for a specific condition, it is realeased by other thread using the methods notify() and notifyAll();
-- it is only used inside the synchronized bloack and synchrronized methods.
eg : -- needs more clarity on this ???
Visibility And Atomicity
Visibility : is about seeing or getting most up to date information of any object, while working on a multithreaded environment we end up having the
we might encounter with stale data if two threads are working symyltaniously.
solution is : volatile key word and synchronized block.
Example :
private static volatile boolean stopRequested = false; -- everytime you update resourse. it is intemated to all the other
data threads who are accessing them.
Atomicity : is Race condition,
were we encounter the situation at which two threads might update the same resource incompletly.
which might lead to currupted data.
Operations as single individual unit.
using atomic integers and concurrent locks packages..
Example : need to get more clarity on this.