Skip to content

Commit 35582de

Browse files
committed
Use System.nanoTime() for Random seed in SocketUtils
Prior to this commit, SocketUtils used System.currentTimeMillis() for the seed for the java.util.Random instance used internally. The use of the milliseconds value returned by currentTimeMillis() can lead to collisions for randomly selected free ports for tests executing in parallel on the same computer. This commit therefore switches to System.nanoTime() for the Random seed used in SocketUtils in an attempt to avoid such collisions for tests executing in parallel in different JVMs on the same computer. Closes gh-25321
1 parent 008a0a1 commit 35582de

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

spring-core/src/main/java/org/springframework/util/SocketUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -54,7 +54,7 @@ public class SocketUtils {
5454
public static final int PORT_RANGE_MAX = 65535;
5555

5656

57-
private static final Random random = new Random(System.currentTimeMillis());
57+
private static final Random random = new Random(System.nanoTime());
5858

5959

6060
/**

0 commit comments

Comments
 (0)