| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,33 @@ | |||
| 1 | + package com.winterbe.java8.samples.concurrent; | ||
| 2 | + | ||
| 3 | + import java.util.concurrent.ConcurrentHashMap; | ||
| 4 | + import java.util.concurrent.ForkJoinPool; | ||
| 5 | + | ||
| 6 | + /** | ||
| 7 | + * @author Benjamin Winterberg | ||
| 8 | + */ | ||
| 9 | + public class ConcurrentHashMap1 { | ||
| 10 | + | ||
| 11 | + public static void main(String[] args) { | ||
| 12 | + testForEach(); | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + private static void testForEach() { | ||
| 16 | + ConcurrentHashMap<String, String> map = new ConcurrentHashMap<>(); | ||
| 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 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments