所以,我在intellij idea中运行我的java代码,然后出现以下 错误。
然后我尝试将 java SDK 从 v.12 更改为 v.11,其他工作正常的项目输出相同的结果。
这是我试图运行的代码。Deitel How To Program Java 中的示例。
package ConcurrentProgramming.ParallelAndNonParallel;
import java.security.SecureRandom;
import java.text.NumberFormat;
import java.time.Duration;
import java.time.Instant;
import java.util.Arrays;
public class SortComparison {
public static void main(String[] args) {
SecureRandom random = new SecureRandom();
int[] array1 = random.ints(15_000_000).toArray();
int[] array2 = new int[array1.length];
System.arraycopy(array1, 0, array2, 0, array1.length);
System.out.println("Starting sort");
Instant sortStart = Instant.now();
Arrays.sort(array1);
Instant sortEnd = Instant.now();
long sortTime = Duration.between(sortStart, sortEnd).toMillis();
System.out.printf("Total time in milliseconds: %d%n%n", sortTime);
System.out.println("Starting parallelSort");
Instant parallelSortStart = Instant.now();
Arrays.parallelSort(array2);
Instant parallelSortEnd = Instant.now();
long parallelSortTime =
Duration.between(parallelSortStart, parallelSortEnd).toMillis();
System.out.printf("Total time in milliseconds: %d%n%n",
parallelSortTime);
String percentage = NumberFormat.getPercentInstance().format(
(double) sortTime / parallelSortTime);
System.out.printf("\nsort took %s more time than parallelSort%n",
percentage);
}
}
犯罪嫌疑人X
相关分类