-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathTest.java
More file actions
57 lines (45 loc) · 950 Bytes
/
Test.java
File metadata and controls
57 lines (45 loc) · 950 Bytes
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
45
46
47
48
49
50
51
52
53
54
55
56
57
class SynchSetUnsynchGet {
private static int var;
public synchronized void setA(int a) {
this.var = a;
}
public synchronized int getA() {
return var; // ok get is synchronized
}
public synchronized void setB(int a) {
this.var = a;
}
public int getB() {
return var; // bad
}
public synchronized void setC(int a) {
this.var = a;
}
public int getC() {
synchronized (this) {
return var; // ok get uses synchronized block
}
}
public void setD(int a) {
this.var = a;
}
public int getD() {
return var; // ok set is not synchronized
}
public synchronized void setE(int a) {
this.var = a;
}
public int getE() {
synchronized (String.class) {
return var; // bad synchronize on wrong thing
}
}
public static synchronized void setF(int a) {
var = a;
}
public static int getF() {
synchronized (SynchSetUnsynchGet.class) {
return var; // ok get uses synchronized block
}
}
}