You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -62,29 +61,30 @@ public static void main(String args[]) {
62
61
classPrintDemo {
63
62
publicvoidprintCount() {
64
63
try {
64
+
System.out.println(Thread.currentThread().getName() + " is working now..");
65
65
for (inti = 5; i > 0; i--) {
66
-
System.out.println("Counter --- " + i);
66
+
System.out.println("Counter --- " + i + " from thread: " + Thread.currentThread().getName());
67
67
}
68
68
} catch (Exceptione) {
69
69
System.out.println("Thread interrupted.");
70
70
}
71
71
}
72
-
73
72
}
74
73
75
74
classThreadDemoextendsThread {
76
75
privateThreadt;
77
76
privateStringthreadName;
78
-
PrintDemoPD;
77
+
PrintDemoprintDemo;
79
78
80
79
ThreadDemo(Stringname, PrintDemopd) {
81
80
threadName = name;
82
-
PD = pd;
81
+
printDemo = pd;
83
82
}
84
83
85
84
publicvoidrun() {
86
-
synchronized (PD) {//Here's all the difference between the two examples! It uses this synchronized keyword to identify the resources that need to be synchronized!
87
-
PD.printCount();
85
+
//Here's all the difference between the two examples! It uses this synchronized keyword to identify the resources that need to be synchronized!
0 commit comments