-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathClock.java
More file actions
62 lines (56 loc) · 1.29 KB
/
Copy pathClock.java
File metadata and controls
62 lines (56 loc) · 1.29 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
package singleton;
/**
* @Title: Clock.java
*
* @Package singleton
*
* @Description: the Clock class, which defines the ops and attrs of a Clock
*
* @author Jiajie
*
* @date 2020/11/24
*/
public class Clock {
private volatile static Clock clock;
/**
*
* @Description: Constructor, which initialize the time with default value
*/
private Clock() {
time = "Loading...";
};
/**
* @Description: use double-checked locking to ensure the singleton
* volatile guarantees that the code will be correct even if the
* java virtual machine performs instruction reordering on it.
*
* @return: the static Clock
*/
public static Clock getClock() {
if (clock == null) {
synchronized (Clock.class) {
if (clock == null) {
clock = new Clock();
}
}
}
return clock;
}
private String time;
/**
* @Description: set the current time
*
* @param currentTime: the current time
*/
public void setTime(String currentTime) {
time = currentTime;
}
/**
* @Description: get the current time
*
* @return: the current time
*/
public String getTime() {
return time;
}
}