-
Sub-task
-
Resolution: Unresolved
-
P4
-
8
-
Windows7x64, JDK8 b107 x64
-
Fix Understood
-
b107
-
x86
-
windows_7
Following code:
import java.util.*;
public class Test {
public static void main(String[] args) {
StringJoiner expected = new StringJoiner("\n");
expected.add("expected:");
StringJoiner actual = new StringJoiner("\n");
actual.add("actual:");
Iterator<Double> i = new SplittableRandom(0).doubles(8).distinct().iterator();
while (i.hasNext()) {
expected.add(String.valueOf(i.next()));
}
i = new SplittableRandom(0).doubles(8).distinct().parallel().iterator();
while (i.hasNext()) {
actual.add(String.valueOf(i.next()));
}
System.out.println(expected);
System.out.println(actual);
}
}
Produces following output:
expected:
0.6118225421857174
0.8243869101616611
0.8435259660697864
0.4175532166907524
0.1350922166954046
0.13871074418376472
0.24279104418383668
0.2419412935695664
actual:
0.10047975177649981
0.4886723680988455
0.24952460161236745
0.2001101735985169
0.4175532166907524
0.8603064296150352
0.7058812188621817
0.13950492113400426
However we should have received the identical result according to following assertion from specification:
Except for operations identified as explicitly nondeterministic, such as findAny(), whether a stream executes sequentially or in parallel should not change the result of the computation.
This assertion could be found here:
http://jre.us.oracle.com/java/re/jdk/8/promoted/latest/doc/api/java/util/stream/package-summary.html
import java.util.*;
public class Test {
public static void main(String[] args) {
StringJoiner expected = new StringJoiner("\n");
expected.add("expected:");
StringJoiner actual = new StringJoiner("\n");
actual.add("actual:");
Iterator<Double> i = new SplittableRandom(0).doubles(8).distinct().iterator();
while (i.hasNext()) {
expected.add(String.valueOf(i.next()));
}
i = new SplittableRandom(0).doubles(8).distinct().parallel().iterator();
while (i.hasNext()) {
actual.add(String.valueOf(i.next()));
}
System.out.println(expected);
System.out.println(actual);
}
}
Produces following output:
expected:
0.6118225421857174
0.8243869101616611
0.8435259660697864
0.4175532166907524
0.1350922166954046
0.13871074418376472
0.24279104418383668
0.2419412935695664
actual:
0.10047975177649981
0.4886723680988455
0.24952460161236745
0.2001101735985169
0.4175532166907524
0.8603064296150352
0.7058812188621817
0.13950492113400426
However we should have received the identical result according to following assertion from specification:
Except for operations identified as explicitly nondeterministic, such as findAny(), whether a stream executes sequentially or in parallel should not change the result of the computation.
This assertion could be found here:
http://jre.us.oracle.com/java/re/jdk/8/promoted/latest/doc/api/java/util/stream/package-summary.html
- relates to
-
JDK-8022807 j.u.SplittableRandom does not (always) generate identical sequences of values for the same seed if parallel stream is consumed
- Resolved