diff options
author | Santo Cariotti <santo@dcariotti.me> | 2021-12-01 23:10:21 +0100 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2021-12-01 23:10:21 +0100 |
commit | eb4161840396b65cb8e018db042eb8ae101b2646 (patch) | |
tree | 2629f322305a639e96964d17edad39cb137a3f77 /Year_3/TSDWL/ex_20191218/Thread2.java | |
parent | 071a8ee7b742498dc4714d06eaf55f6a40aeb7fa (diff) |
tsdwl: adds in java
Diffstat (limited to 'Year_3/TSDWL/ex_20191218/Thread2.java')
-rw-r--r-- | Year_3/TSDWL/ex_20191218/Thread2.java | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Year_3/TSDWL/ex_20191218/Thread2.java b/Year_3/TSDWL/ex_20191218/Thread2.java new file mode 100644 index 0000000..35cb3fe --- /dev/null +++ b/Year_3/TSDWL/ex_20191218/Thread2.java @@ -0,0 +1,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(); + } + } + } +} |