-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathSynchronized.java
43 lines (37 loc) · 1.2 KB
/
Synchronized.java
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
public class Synchronized {
public static void main(String[] args) {
Synchronized obj = new Synchronized();
synchronized (obj) {
System.out.println("Hello");
}
try {
testtry();
} catch (Exception e) {
System.out.println("caught e: " + e.getMessage());
}
try {
synchronized (obj) {
throw new Exception("inner throw");
}
} catch (Exception e) {
System.out.println("caught e: " + e.getMessage());
}
synchronized (obj) {
System.out.println("Acquired lock after exceptions");
obj.doStuff();
}
}
public static synchronized void testtry() throws Exception {
System.out.println("entertest");
throw new Exception("message1");
}
public synchronized void doStuff() {
System.out.println("acquired owned lock succeeded");
}
public static void synchronized_enter(Object o) {
//checking that the desugar name for monitor enter isn't used as
//special constant anywhere. This method should never be called
System.out.println("yesss");
return;
}
}