uniqueElements in parallel mode - encounter order
Georgiy Rakov
georgiy.rakov at oracle.com
Fri Nov 30 06:26:40 PST 2012
Hello,
*
uniqueElements()* method working in parallel mode does not preserve
encounter order now. Consider following code. *result *will always
contain sorted numbers in spite of shuffling, i. e. [0, 1, 2, 3, 4, 5,
6, 7, 8, 9]. I could suppose this is the used algorithm artifact.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
public class UniqueElementsIssue1 {
public static void main(String arg[]) {
ArrayList<Integer> data = new ArrayList<>();
for (int i = 0; i<10; ++i) {
for (int k = 0; k<30; ++k) {
data.add(i);
}
}
Collections.shuffle(data);
ArrayList<Integer> result = new ArrayList<>();
Arrays.parallel(data.toArray(new
Integer[0])).uniqueElements().into(result);
}
}
While for sequential mode (Arrays.asStream) the encounter order is
preserved.
Could you please tell if this is considered as expected behavior and
will be showed in spec; for instance something like following could be
there.
/Having been called on stream in sequential mode, UniqueElements
preserve encounter order.
Having been called on stream in parallel mode, UniqueElements doesn't
preserve encounter order.
/
The code above is attached for your convenience.
Thanks,
Georgiy.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: UniqueElementsIssue1.java
Url: http://mail.openjdk.java.net/pipermail/lambda-dev/attachments/20121130/c34b7056/UniqueElementsIssue1.java
More information about the lambda-dev
mailing list