1
public class ThreadA
2

{
3
public static void main(String[] args)
4
{
5
ThreadB b = new ThreadB();
6
b.start();
7
8
//synchronized(b)
9
//{
10
//try
11
{
12
System.out.println("Waiting for b to complete
");
13
//b.wait();
14
}
15
//catch (InterruptedException e)
16
{
17
18
}
19
20
System.out.println("Total is " + b.total);
21
//}
22
}
23
}
24
25
class ThreadB extends Thread
26

{
27
int total;
28
29
public void run()
30
{
31
synchronized(this)
32
{
33
for(int i=0; i<100; i++)
34
{
35
total = total + i;
36
}
37
notify();
38
}
39
}
40
}

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

40
