On Wed, 14 Jun 2023 11:02:04 GMT, Daniel Fuchs <[email protected]> wrote:

>> The HttpClient uses `Instant.now()` to create deadlines for timeouts. This 
>> could have undesirable effects since `Instant.now()` is linked to the wall 
>> clock, which is not monotonic. This fix changes the HttpClient to use a 
>> monotonic instant source based on `System.nanoTime()` for the purpose of 
>> setting and comparing deadlines.
>
> Daniel Fuchs has updated the pull request with a new target base due to a 
> merge or a rebase. The incremental webrev excludes the unrelated changes 
> brought in by the merge/rebase. The pull request contains two additional 
> commits since the last revision:
> 
>  - Merge branch 'master' into TimeSource
>  - 8309939

src/java.net.http/share/classes/jdk/internal/net/http/common/TimeSource.java 
line 41:

> 39:  * of monotonicity than the {@link System#nanoTime()} it is based on.
> 40:  */
> 41: public final class TimeSource implements InstantSource {

Given that all instances of TimeSource are essentially the same (through the 
use of shared `nanoSource`), can we add a private constructor and make this 
class a singleton?

src/java.net.http/share/classes/jdk/internal/net/http/common/TimeSource.java 
line 46:

> 44:     private static final TimeSource SOURCE = new TimeSource();
> 45: 
> 46:     private static final class NanoSource implements InstantSource {

This class doesn't need to implement InstantSource

src/java.net.http/share/classes/jdk/internal/net/http/common/TimeSource.java 
line 59:

> 57: 
> 58:         @Override
> 59:         public Instant instant() {

This method is not used anywhere

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/14450#discussion_r1229507872
PR Review Comment: https://git.openjdk.org/jdk/pull/14450#discussion_r1229505949
PR Review Comment: https://git.openjdk.org/jdk/pull/14450#discussion_r1229506241

Reply via email to