StreamOpFlag.* and OutOfMemoryError when going parall
Christian Mallwitz
c.mallwitz at gmail.com
Wed Dec 5 15:39:34 PST 2012
I was experimenting with a few lambda examples and tried to generate
the first 1000 prime numbers by
- create an iterator to generating an infinite amount numbers
- filter prime numbers
- limit the filtered number to 1000
The serial version is working as expected keeping one CPU core busy.
My hope was that the parallel version would do the prime number
testing bit on all cores and then stop when it has collected 1000
prime numbers (and stop pulling further numbers from the iterator to
test them for primality)
As Brian pointed out, because the limit() isn't fully lazy, this
results in an OutOfMemoryError because actually calculating _all_
prime numbers this way and _then_ limit the result set isn't really an
option. Now I wonder whether I could build a better limit() version
myself...
Christian
On Wed, Dec 5, 2012 at 7:11 PM, Remi Forax <forax at univ-mlv.fr> wrote:
> On 12/05/2012 07:54 PM, Christian Mallwitz wrote:
>> Very well :-)
>>
>> Leaving the parallel aspect aside, If I just wanted to find the first
>> n prime numbers based on a possibly infinity stream of numbers (I
>> don't want to use a Collection with a known size), is there another
>> 'officially' approved way to covert an Iterator to a Stream (instead
>> of using Streams.stream())?
>
> I understand what you want to do but I don't understand how you want the
> code to work in parallel.
>
>>
>> Regarding a fully lazy, parallel limit() and its future: does 'future'
>> mean pre- or post-JDK8?
>>
>> Cheers!
>> Christian
>
> regards,
> Rémi
>
>
More information about the lambda-dev
mailing list