parallelStream()比stream()慢

时间:2019-03-10 10:56:57

标签: java concurrency parallel-processing functional-programming java-stream

我的这段代码运行缓慢

userMenus
                .forEach(
                        ccy -> configuredAlerts
                                .add(new ConfiguredAlerts(
                                        ccy, Stream
                                                .concat(pricealertsXMenu.stream()
                                                        .filter(pac -> pac.getMenu().equals(ccy))

                                                        .map(pac -> new MenuAlarm("priceAlert",pac.getPriceAlert().getMenuAlertGroup().getName()))
                                                        .distinct(),

                                                        percentagealertsXMenu.stream()
                                                        .filter(pac -> pac.getMenu().equals(ccy))
                                                                .map(pac -> new MenuAlarm("percentageAlert",pac.getPercentageAlert().getMenuAlertGroup().getName()))
                                                                .distinct())

                                                .distinct().collect(toList()))));

我将.stream()替换为.parallelStream()以使其更快,但运行速度甚至更慢

0 个答案:

没有答案