Parallel message unmarshalling from a token delimited input stream with Java8 stream API

六眼飞鱼酱① 提交于 2019-12-08 04:48:33

One problem is that the parallelStream ForkJoinPool use the current thread to contribute to the pool. This means there is no current thread free to perform this actions.

The only realistic way of doing this is to kick this off in a single threaded executor to start the parallelStream doing a forEach writing to a fixed size BlockingQueue and the current thread could consume the results of the queue.

I suspect you would be better off re-writing your code so that pullNext isn't required. e.g.

Iterable<String> stash = Iterables.cycle("one", "two", "three");
Iterator<String> sink = StreamSupport.stream(stash.spliterator(), true).
    .parallel()
    .map(x -> x + "-unmarshalled")
    .forEach(x -> process(x));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!