且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java 8:如何将for循环转换为并行运行?

更新时间:2023-09-26 22:40:16

我在Java 8中使用了以下代码,它确实工作。我能够将批处理作业从28分钟缩短到3:39分钟。

I used the following code in Java 8 and it did the work. I was able to reduce the batch job to run from 28 minutes to 3:39 minutes.

IntStream.range(0, 100000).parallel().forEach(i->{
     restTemplate.exchange(url, HttpMethod.GET, request, String.class);
}
});