forked from winterbe/java8-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConcurrency1.java
More file actions
37 lines (28 loc) · 986 Bytes
/
Concurrency1.java
File metadata and controls
37 lines (28 loc) · 986 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
package com.winterbe.java8.samples.misc;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
/**
* @author Benjamin Winterberg
*/
public class Concurrency1 {
public static void main(String[] args) {
ConcurrentHashMap<Integer, UUID> concurrentHashMap = new ConcurrentHashMap<>();
for (int i = 0; i < 100; i++) {
concurrentHashMap.put(i, UUID.randomUUID());
}
int threshold = 1;
concurrentHashMap.forEachValue(threshold, System.out::println);
concurrentHashMap.forEach((id, uuid) -> {
if (id % 10 == 0) {
System.out.println(String.format("%s: %s", id, uuid));
}
});
UUID searchResult = concurrentHashMap.search(threshold, (id, uuid) -> {
if (String.valueOf(uuid).startsWith(String.valueOf(id))) {
return uuid;
}
return null;
});
System.out.println(searchResult);
}
}