Skip to content

Commit 496d935

Browse files
authored
Create staticSynchronization.java
1 parent dfd8d69 commit 496d935

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

staticSynchronization.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
class Table{
2+
3+
synchronized static void printTable(int n){
4+
5+
for (int i = 1; i <=3; i++){
6+
7+
System.out.println(n * i);
8+
try {
9+
} catch (Exception e) {
10+
System.out.println(e);
11+
}
12+
}
13+
}
14+
}
15+
16+
class Thread1 extends Thread{
17+
18+
public void run() {
19+
Table.printTable(1);
20+
}
21+
}
22+
23+
class Thread2 extends Thread {
24+
public void run() {
25+
Table.printTable(10);
26+
}
27+
}
28+
29+
public class staticSynchronization {
30+
31+
public static void main(String[] args){
32+
33+
Thread1 t1 = new Thread1();
34+
Thread2 t2 = new Thread2();
35+
t1.start();
36+
t2.start();
37+
}
38+
}

0 commit comments

Comments
 (0)