Stream parallel() / sequential() question. (original) (raw)
Brian Goetz brian.goetz at oracle.com
Thu Apr 4 07:05:11 PDT 2013
- Previous message: Stream parallel() / sequential() question.
- Next message: Stream parallel() / sequential() question.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
This was simplified recently.
There is one sequential/parallel bit for the whole pipeline. The stream starts off with it set one way or the other. These calls overwrite it. The bit is only acted on when you actually start the computation (invoke the terminal operation.)
On 4/4/2013 9:21 AM, Boaz Nahum wrote:
When I invoked parallel() or sequential() how backward it goes ?
Let me explain, I wrote a simple Consumer that report how many different threads used to run it: source. parallel().peek(new ThreadReporter("Segement 1 parallel")). sequential().peek(new ThreadReporter("Segement 2 sequential")). parallel().peek(new ThreadReporter("Segement 3 parallel")). sequential().peek(new ThreadReporter("Segement 4 sequential")).forEach((t) -> {});
private static class ThreadReporter implements Consumer { @Override public void accept(Integer integer) { threads.put(Thread.currentThread(), true); } public void report() { System.out.println("Name +'" + name + "': " + threads.size() + " Thread(s)"); } }
- Previous message: Stream parallel() / sequential() question.
- Next message: Stream parallel() / sequential() question.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]