mxsm commented on code in PR #5925:
URL: https://github.com/apache/rocketmq/pull/5925#discussion_r1087906656


##########
common/src/main/java/org/apache/rocketmq/common/UtilAll.java:
##########
@@ -83,15 +84,18 @@ public static int getPid() {
     }
 
     public static void sleep(long sleepMs) {
-        if (sleepMs < 0) {
+        sleep(sleepMs, TimeUnit.MILLISECONDS);
+    }
+
+    public static void sleep(long timeOut, TimeUnit timeUnit) {
+        if (null == timeUnit) {
             return;
         }
         try {
-            Thread.sleep(sleepMs);
-        } catch (Throwable ignored) {
+            timeUnit.sleep(timeOut);
+        } catch (InterruptedException ignored) {

Review Comment:
   @caigy 156
   timeUnit.sleep(x)will call Thread.sleep after validating that the timeout is 
positive. Simplifies the previous code.
   Other than that, the only difference is readability and using TimeUnitis 
probably easier to understand for non-obvious durations (for example: 
Thread.sleep(180000) vs. TimeUnit.MINUTES.sleep(3)). and I've adjusted the 
thrown exception to be Throwable.
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to