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
38 lines (33 loc) · 1.39 KB

File metadata and controls

38 lines (33 loc) · 1.39 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
class ThreadB extends Thread // this thread performing updation so called notify method
{
int tot = 0;
public void run() {
synchronized (this) {
/* 1 */System.out.println("child thread start calculation");
for (int i = 1; i <= 100; i++) {
tot += i;
}
/* 2 */System.out.println("Child thread trying to give notification");
/* 3 */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 interthreadcommunication3 // this thred expecting updation so called wait method
{
public static void main(String[] args) throws InterruptedException {
ThreadB b = new ThreadB();
b.start();
Thread.sleep(10000);
synchronized (b) {
/* 4 */System.out.println("main thread trying to call wait method");
//Problem in interthreadcommunication2.java solved in just below statement
b.wait(10000);//main therad wait only for 10 sec if not notificaion came then rest of code is executes
// after calling this main thread go into waiting state
//here thread does not get noification only executed rest of part present below
/*5*/System.out.println(b.tot);
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.