summaryrefslogtreecommitdiff
path: root/Year_3/TSDWL/ex_20191218/Thread2.java
diff options
context:
space:
mode:
Diffstat (limited to 'Year_3/TSDWL/ex_20191218/Thread2.java')
-rw-r--r--Year_3/TSDWL/ex_20191218/Thread2.java28
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();
+ }
+ }
+ }
+}