-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTvRemote.java
40 lines (32 loc) · 989 Bytes
/
TvRemote.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
package brainOut;
/**
* @author VIREN
*
* Singleton pattern using double checking locking and synchronized
* keyword so that , this class remain singleton in multi-threaded
* Environment. the synchronized block is used inside the if condition
* with an additional check to ensure that only one instance of
* singleton class is created
*/
public class TvRemote {
private final String model;
private final String tv;
private static TvRemote tvRemote = null;
private TvRemote() {
this.model = "10x";
this.tv = "Generic";
}
public static TvRemote get() {
if (tvRemote == null)
synchronized (TvRemote.class) {
if (tvRemote == null) {
tvRemote = new TvRemote();
}
}
return tvRemote;
}
public void process(String operationName) {
System.out.println("processng " + operationName + "... on " + tv);
System.out.println(operationName + "processed on " + tv);
}
}