On Tue, 17 Nov 2026 15:18:34 GMT, Volkan Yazici <[email protected]> wrote:

>> Switch `jdk.httpserver` from wall clock to a monotonic one. This effectively 
>> fixes elapsed time measurements and scheduled event fire instants. Bonus: 
>> improves the test stability.
>> 
>> In short, replaced the `System.currentTimeMillis()` & `java.util.Timer` 
>> combination with the `System.nanoTime()` & `ScheduledExecutorService` 
>> alternative.
>> 
>> ---------
>> - [X] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> Volkan Yazici has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Switch from `scheduleAtFixedRate()` to `scheduleWithFixedDelay()`

src/jdk.httpserver/share/classes/sun/net/httpserver/ServerImpl.java line 1253:

> 1251:     }
> 1252: 
> 1253: }

Suggestion:

    final static long startNanos = System.nanoTime();
    /**
     * A monotonic clock substitute of {@link System#currentTimeMillis()}, which
     * uses wall clock, and hence, is unsuitable for elapsed time measurements.
     */
    private static long monotonicInstantMillis() {
        return TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNanos);
    }

}

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

PR Review Comment: https://git.openjdk.org/jdk/pull/33890#discussion_r4601685574

Reply via email to