4

Reading Java 8's streaming API for parallelism: https://docs.oracle.com/javase/tutorial/collections/streams/parallelism.html

It's not clear how to tune the number of threads to use when using this streaming API's parallelism?

Plan to run this on a very specific type of machine and a consistent data types, so I was thinking I can benchmark it over a set of different settings then use the best number of threads.

0

1 Answer 1

4

The stream API does not support any tuning parameters. The library is designed to work as effectively as possible regardless of the particular machine's characteristics.

Sign up to request clarification or add additional context in comments.

8 Comments

Then using traditional threads would be appropriate?
I didn't say that. I would trust the stream API to be better implemented than anything you wrote from scratch, even if you had information about the machine.
To put it another way, there are no tuning parameters because it knows better than you.
I wouldn't say that it ALWAYS knows better than you. Tuning would have been useful when the processing is IO-bound. Consider something like map(StockUtil::getPrice()) that goes to a web service to get the price for the 1000 ticker symbols in the list.
@LouisWasserman is this intention documented somewhere? Because for me, Streams feel like a (general purpose) language construct (it is java.*lang*.stream.Stream after all). In some cases I might not even know (or care) how my data is processed (in my concrete case I'm looking into caching right now - that will actually change the how is my data processed during runtime).
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.