Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
39 lines (35 loc) · 1.3 KB

File metadata and controls

39 lines (35 loc) · 1.3 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
37
38
39
class ThreadB extends Thread //this thread performing updation so called notify method
{
int tot=0;
public void run()
{
synchronized(this)
{
/*2*/System.out.println("child thread start calculation");
for (int i = 1; i <= 100; i++) {
tot += i;
}
/*3*/System.out.println("Child thread trying to give notification");
/*4*/this.notify();//notify method
}
}
}
//Run this code and see o/p and also analyse
//most of time main thread get chance according to that flow indicated by numbers
class interthreadcommunication1 //this thred expecting updation so called wait method
{
public static void main(String[] args) throws InterruptedException
{
ThreadB b=new ThreadB();
b.start();
//most of time main thread got a chance
synchronized(b)
{
/*1*/System.out.println("main thread trying to call wait method");
b.wait();//after calling this main thread go into waiting state
//as wait method is called by main thread so immediately releases lock and it goes into waiting state
/*5*/System.out.println("main thread got notificaion ");
/*6*/System.out.println(b.tot);
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.