gortiz commented on code in PR #15277: URL: https://github.com/apache/pinot/pull/15277#discussion_r2005668438
########## pinot-common/src/main/java/org/apache/pinot/common/utils/Timer.java: ########## @@ -18,32 +18,34 @@ */ package org.apache.pinot.common.utils; +import java.util.concurrent.TimeUnit; + /** * Utility class that works with a timeout in milliseconds and provides methods to check remaining time and expiration. */ public class Timer { - private final long _timeoutMillis; - private final long _startTime; + private final long _startNs; + private final long _deadlineNs; + private final ClockNs _clock; - /** - * Initializes the Timer with the specified timeout in milliseconds. - * - * @param timeoutMillis the timeout duration in milliseconds - */ - public Timer(long timeoutMillis) { - _timeoutMillis = timeoutMillis; - _startTime = System.currentTimeMillis(); + public Timer(Long timeout, TimeUnit timeUnit) { + this(System::nanoTime, timeout, timeUnit); + } + + public Timer(ClockNs clock, Long timeout, TimeUnit timeUnit) { + _clock = clock; + _startNs = _clock.nanos(); + _deadlineNs = timeUnit.toNanos(timeout) + _clock.nanos(); } /** * Returns the remaining time in milliseconds. If the timeout has expired, it returns 0. * * @return the remaining time in milliseconds */ - public long getRemainingTime() { - long elapsedTime = System.currentTimeMillis() - _startTime; - long remainingTime = _timeoutMillis - elapsedTime; - return Math.max(remainingTime, 0); + public long getRemainingTimeMs() { + long remainingNs = _deadlineNs - _clock.nanos(); + return Math.max(remainingNs / 1000, 0); Review Comment: Yep. My bad. BTW, I've changed this class because nanos are recommended over millis and also because it was useful to add some extra methods -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org