Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit97c2081

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parentsd3dda84 +780bfa6 commit97c2081

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
packagecom.winterbe.java8.samples.concurrent;
2+
3+
importjava.util.concurrent.ConcurrentHashMap;
4+
importjava.util.concurrent.ForkJoinPool;
5+
6+
/**
7+
* @author Benjamin Winterberg
8+
*/
9+
publicclassConcurrentHashMap1 {
10+
11+
publicstaticvoidmain(String[]args) {
12+
testForEach();
13+
}
14+
15+
privatestaticvoidtestForEach() {
16+
ConcurrentHashMap<String,String>map =newConcurrentHashMap<>();
17+
map.putIfAbsent("foo","bar");
18+
map.putIfAbsent("han","solo");
19+
map.putIfAbsent("r2","d2");
20+
map.putIfAbsent("c3","p0");
21+
22+
23+
// map.forEach((key, value) -> System.out.printf("key: %s; value: %s\n", key, value));
24+
25+
System.out.println("Parallelism: " +ForkJoinPool.getCommonPoolParallelism());
26+
27+
map.forEach(1, (key,value) ->System.out.printf("key: %s; value: %s; thread: %s\n",key,value,Thread.currentThread().getName()));
28+
// map.forEach(5, (key, value) -> System.out.printf("key: %s; value: %s; thread: %s\n", key, value, Thread.currentThread().getName()));
29+
30+
System.out.println(map.mappingCount());
31+
}
32+
33+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp