summaryrefslogtreecommitdiff
path: root/Year_3/TSDWL/ex_20191218/Thread2.java
blob: 35cb3fe89c5885ec798e9f31e20cf7197fba0bc0 (plain)
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
public class Thread2 extends Thread {
    Shared mem;
    public Thread2(Shared mem) {
        super();
        this.mem = mem;
    }

    public void run() {
        int m;

        while (true) {
            try {
                Thread.sleep(300);
            } catch (InterruptedException e) {
                e.printStackTrace();
                break;
            }
            synchronized(mem) {
                if (mem.get() == -1) {
                    break;
                }

                System.out.println("\t\t\tThread 2, notify thread 1");
                mem.notify();
            }
        }
    }
}