import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.TimeUnit; public class Streams12 { public static void main(String[] args) {
List<String> strings = Arrays.asList("a1", "a2", "b1", "c2", "c1"); // test1();
// test2(strings);
test3(strings);
// test4();
} private static void test4() {
List<String> values = new ArrayList<>(100);
for (int i = 0; i < 100; i++) {
UUID uuid = UUID.randomUUID();
values.add(uuid.toString());
} // sequential long t0 = System.nanoTime(); long count = values
.parallelStream()
.sorted((s1, s2) -> {
System.out.format("sort: %s <> %s [%s]\n", s1, s2, Thread.currentThread().getName());
return s1.compareTo(s2);
})
.count();
System.out.println(count); long t1 = System.nanoTime(); long millis = TimeUnit.NANOSECONDS.toMillis(t1 - t0);
System.out.println(String.format("parallel sort took: %d ms", millis));
} private static void test3(List<String> strings) {
strings
.parallelStream()
.filter(s -> {
System.out.format("filter: %s [%s]\n", s, Thread.currentThread().getName());
return true;
})
.map(s -> {
System.out.format("map: %s [%s]\n", s, Thread.currentThread().getName());
return s.toUpperCase();
})
.sorted((s1, s2) -> {
System.out.format("sort: %s <> %s [%s]\n", s1, s2, Thread.currentThread().getName());
return s1.compareTo(s2);
})
.forEach(s -> System.out.format("forEach: %s [%s]\n", s, Thread.currentThread().getName()));
} private static void test2(List<String> strings) {
strings
.parallelStream()
.filter(s -> {
System.out.format("filter: %s [%s]\n", s, Thread.currentThread().getName());
return true;
})
.map(s -> {
System.out.format("map: %s [%s]\n", s, Thread.currentThread().getName());
return s.toUpperCase();
})
.forEach(s -> System.out.format("forEach: %s [%s]\n", s, Thread.currentThread().getName()));
} private static void test1() {
// -Djava.util.concurrent.ForkJoinPool.common.parallelism=5 ForkJoinPool commonPool = ForkJoinPool.commonPool();
System.out.println(commonPool.getParallelism());
}
}

最新文章

  1. CMS系统存储路径
  2. 命名空间“System.Web”中不存在类型或命名空间名称“Optimization”(是否缺少程序集引用?)
  3. Android中使用Gson解析JSON数据的两种方法
  4. 腾讯数据总监:运营人员必须掌握的APP基础数据分析体系(没有比这篇更系统全面的)
  5. [LeetCode]题解(python):082 - Remove Duplicates from Sorted List II
  6. noip知识点总结之--贪心
  7. nethogs 实时查看进程使用流量情况。
  8. String 两种实例化方式的区别
  9. UVa 10132 - File Fragmentation
  10. win10如何快速扫描-上海IT外包
  11. OJ:自己实现一个简单的 priority_queue
  12. java生成UUID
  13. Unity3D动态生成多边形
  14. 计算apk包的安装之后占用空间以及运行时占用内存
  15. JVM调优——之CMS 常见参数解析
  16. jeecg 主-附表生成代码例子
  17. Call to undefined function think\finfo_open()
  18. Linux下通过管道杀死所有与tomcat相关的进程
  19. 初识DOM
  20. linux添加磁盘空间

热门文章

  1. [Agc028B]Removing Blocks_排列组合
  2. Python if __name__ == &#39;__main__&#39;: 理解
  3. Nginx03---重装
  4. 数据库(mysql和oracle)
  5. github骚操作
  6. Cache的一些总结
  7. php--正则(手机号码)
  8. VisualVM的使用
  9. 忘记root密码,修改方法
  10. CentOS开机启动进度条卡死问题