blob: 506c60f8376019b468e223bd50614b78422d8073 (
plain)
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
44
|
// Copyright 2008 The Android Open Source Project
/**
* Exercise monitors.
*/
public class Monitor {
public static int mVal = 0;
public synchronized void subTest() {
Object obj = new Object();
synchronized (obj) {
mVal++;
obj = null; // does NOT cause a failure on exit
Main.assertTrue(obj == null);
}
}
public static void run() {
System.out.println("Monitor.run");
Object obj = null;
try {
synchronized (obj) {
mVal++;
}
Main.assertTrue(false);
} catch (NullPointerException npe) {
/* expected */
}
obj = new Object();
synchronized (obj) {
mVal++;
}
new Monitor().subTest();
Main.assertTrue(mVal == 2);
}
}
|