RFR: 8309939: HttpClient should not use Instant.now() as Instant source for deadlines [v4]

Roger Riggs rriggs at openjdk.org
Wed Jun 14 17:34:56 UTC 2023


On Wed, 14 Jun 2023 15:32:57 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:

>> src/java.net.http/share/classes/jdk/internal/net/http/common/TimeSource.java line 36:
>> 
>>> 34:  * caused by changes to the wall clock. Consequently, callers should use
>>> 35:  * instants returned by this time source solely for the purpose of
>>> 36:  * comparing them with other instants returned by this same time source.
>> 
>> Do not use `Instant` as the value from this time source. It is not comparable with the real Instants and would be misleading and cause bugs.
>
> OK. Here is a version that uses a new class "Deadline" instead of "Instant".

Wrapping the Instant is safe/fine.
However, it could quite a bit simpler (it seems) to just use the raw `long` nanoTime values.
Though milliseconds or seconds would be sufficient for the timeouts.
The complexity of the volatile read and needing to reset the nanoSource could be avoided.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/14450#discussion_r1229952947


More information about the net-dev mailing list