-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsynchronizedLinkedHashMap.java
More file actions
35 lines (29 loc) · 963 Bytes
/
synchronizedLinkedHashMap.java
File metadata and controls
35 lines (29 loc) · 963 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
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
public class synchronizedLinkedHashMap {
public static void main(String[] args) throws Exception {
Thread thread = new Thread();
Map<String, Integer> map = Collections.synchronizedMap(new LinkedHashMap<>());
map.put("a", 1);
map.put("b", 2);
map.put("c", 3);
map.put("d", 4);
map.put("e", 5);
map.put("f", 6);
System.out.println(map);
Map<String, Integer> map1 = new LinkedHashMap<>();
thread.start();
Thread.sleep(1000);
synchronized (map1) {
map1.put("a", 1);
map1.put("b", 2);
map1.put("c", 3);
map1.put("d", 4);
map1.put("e", 5);
map1.put("f", 6);
System.out.println(map1);
}
thread.stop();
}
}