答复: Demo for Parallel Core Collection API
tristan.yan at oracle.com
Tue Feb 4 17:20:33 UTC 2014
Thank you Paul. I was told maybe we will target this on 8u20 if we can't catch 8. Let's do the open review first.
Update as you suggested. Test shows parallel version is faster than sequential version when the input is greater than 100,000.
Inner parallel was eliminated. Also BufferedImage.set is a thread safe method.
Unused hit method was removed.
It's changed into ProbablePrimeNumber. Following your suggestion to use BigInteger.probablePrime method.
发件人: Paul Sandoz
发送时间: Tuesday, February 04, 2014 5:34 PM
收件人: Tristan Yan
抄送: core-libs-dev at openjdk.java.net; Aleksandre Iline; Mikhail Kondratyev
主题: Re: Demo for Parallel Core Collection API
On Feb 4, 2014, at 2:58 AM, Tristan Yan <tristan.yan at oracle.com> wrote:
> Hi Paul
> I know this may be a little bit late.
Yes, likely too late... (see below).
> But I am still asking you review this.
> This is a whole demo code include the stream demo code you reviewed before also included parallel part. There is one other parallel demo that Paul has already pushed.
> Could you please review it again?
- There is no parallel execution; one can write as follows for better splitting:
return IntStream.range(0, n).mapToObj(i -> matrix).
- While the approach is interesting (elegant in terms of the reduction) one is not likely to observe any speed up (did you measure?) since the long value will overflow on the 93rd number . You would need to use BigInteger and a larger number of iterations.
- In rotate/shift/zoom/invert the inner range (over height) should not be parallel, it's just gonna fight for resources with the outer range (over width).
- It's not entirely clear to me if BufferedImage is thread safe to concurrently set the pixels
- hit() method is no longer used.
- better to use ThreadLocalRandom or SplittableRandom, as both of those produce higher quality sequences of random numbers.
- i don't think this example has much value as there are better ways to determine primes. As i have said before, if you want to show a simple example it is better to show the parallel generation of probable primes using BigInteger.
I am sorry to have to say this, i know if you have worked on this for a while, but i think this is now too late to go through another round of reviews.
 Think rabbits!
You can think
More information about the core-libs-dev