amrishlal commented on a change in pull request #7174: URL: https://github.com/apache/pinot/pull/7174#discussion_r685680810
########## File path: pinot-core/src/main/java/org/apache/pinot/core/periodictask/BasePeriodicTask.java ########## @@ -149,27 +182,17 @@ public final synchronized void stop() { } _started = false; - if (_running) { - long startTimeMs = System.currentTimeMillis(); - long remainingTimeMs = MAX_PERIODIC_TASK_STOP_TIME_MILLIS; - LOGGER.info("Task: {} is running, wait for at most {}ms for it to finish", _taskName, remainingTimeMs); - while (_running && remainingTimeMs > 0L) { - long sleepTimeMs = Long.min(remainingTimeMs, 1000L); - remainingTimeMs -= sleepTimeMs; - try { - Thread.sleep(sleepTimeMs); - } catch (InterruptedException e) { - LOGGER.error("Caught InterruptedException while waiting for task: {} to finish", _taskName); - Thread.currentThread().interrupt(); - break; - } - } - long waitTimeMs = System.currentTimeMillis() - startTimeMs; - if (_running) { - LOGGER.warn("Task: {} is not finished in {}ms", waitTimeMs); + try { + // check if task is done running, or wait for the task to get done, by trying to acquire runLock. + if (!_runLock.tryLock(MAX_PERIODIC_TASK_STOP_TIME_MILLIS, TimeUnit.MILLISECONDS)) { + LOGGER.warn("Task: {} did not finish within timeout of {}ms", MAX_PERIODIC_TASK_STOP_TIME_MILLIS); } else { - LOGGER.info("Task: {} is finished in {}ms", waitTimeMs); + LOGGER.warn("Task: {} finished within timeout of {}ms", MAX_PERIODIC_TASK_STOP_TIME_MILLIS); Review comment: Fixed. -- 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