-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFiveton.java
More file actions
64 lines (50 loc) · 1.11 KB
/
Fiveton.java
File metadata and controls
64 lines (50 loc) · 1.11 KB
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
58
59
60
61
62
63
64
public class Fiveton {
private static int INSTANCE_CNT = 0;
private static int NO_INSTANCE = 5;
public static Fiveton INSTANCE[] = null;
public static Fiveton SINGLE_INSTANCE = null;
private Fiveton() {
}
public static Fiveton[] getInstance() {
if (INSTANCE == null) {
synchronized (Fiveton.class) {
for (int i = 0; i < NO_INSTANCE; i++) {
INSTANCE[i] = new Fiveton();
}
}
}
return INSTANCE;
}
/**
* synchronized version
*
* @return
*/
public static Fiveton getSingleInstance() {
if (SINGLE_INSTANCE == null) {
synchronized (Fiveton.class) {
if (INSTANCE_CNT < 5)
SINGLE_INSTANCE = new Fiveton();
INSTANCE_CNT++;
}
}
return SINGLE_INSTANCE;
}
/**
* Double checking of null
* http://www.ibm.com/developerworks/java/library/j-dcl/index.html
* @return
*/
public static Fiveton getSingleInstanceDoubleCheck() {
if (SINGLE_INSTANCE == null) {
synchronized (Fiveton.class) {
if (SINGLE_INSTANCE == null) {
if (INSTANCE_CNT < 5)
SINGLE_INSTANCE = new Fiveton();
INSTANCE_CNT++;
}
}
}
return SINGLE_INSTANCE;
}
}