You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/10/17 00:44:18 UTC

[GitHub] [dubbo] zrlw commented on a change in pull request #8954: [3.0] run timeout task in separate thread to avoid the worker thread blocking

zrlw commented on a change in pull request #8954:
URL: https://github.com/apache/dubbo/pull/8954#discussion_r729738081



##########
File path: dubbo-common/src/main/java/org/apache/dubbo/common/timer/HashedWheelTimer.java
##########
@@ -521,18 +559,18 @@ private long waitForNextTick() {
             long deadline = tickDuration * (tick + 1);
 
             for (; ; ) {
+                // the currentTime will be negative only if the application must keep running last more than 262 years.
                 final long currentTime = System.nanoTime() - startTime;
                 long sleepTimeMs = (deadline - currentTime + 999999) / 1000000;
 
                 if (sleepTimeMs <= 0) {
-                    if (currentTime == Long.MIN_VALUE) {
-                        return -Long.MAX_VALUE;
-                    } else {
-                        return currentTime;
-                    }
+                    return currentTime;

Review comment:
       Long.MIN_VALUE was once used as exit signal, the author add one only for distinguishing.
   the exit signal mechanism is not used anymore.
   you might draw a circle,Long.MIN_VALUE is always on the right of Long.MAX_VALUE. -Long.MAX_VALUE is alway on the right of Long.MIN_VALUE.
   the currenttime caculate the difference of two point on the time circle which perimeter has more than 262 years.

##########
File path: dubbo-common/src/main/java/org/apache/dubbo/common/timer/HashedWheelTimer.java
##########
@@ -521,18 +559,18 @@ private long waitForNextTick() {
             long deadline = tickDuration * (tick + 1);
 
             for (; ; ) {
+                // the currentTime will be negative only if the application must keep running last more than 262 years.
                 final long currentTime = System.nanoTime() - startTime;
                 long sleepTimeMs = (deadline - currentTime + 999999) / 1000000;
 
                 if (sleepTimeMs <= 0) {
-                    if (currentTime == Long.MIN_VALUE) {
-                        return -Long.MAX_VALUE;
-                    } else {
-                        return currentTime;
-                    }
+                    return currentTime;

Review comment:
       Long.MIN_VALUE was once used as exit signal, the author add one only for distinguishing.
   the exit signal mechanism is not used anymore.
   you might draw a circle,Long.MIN_VALUE is always on the right of Long.MAX_VALUE. -Long.MAX_VALUE is always on the right of Long.MIN_VALUE.
   the currenttime caculate the difference of two point on the time circle which perimeter has more than 262 years.

##########
File path: dubbo-common/src/main/java/org/apache/dubbo/common/timer/HashedWheelTimer.java
##########
@@ -521,18 +559,18 @@ private long waitForNextTick() {
             long deadline = tickDuration * (tick + 1);
 
             for (; ; ) {
+                // the currentTime will be negative only if the application must keep running last more than 262 years.
                 final long currentTime = System.nanoTime() - startTime;
                 long sleepTimeMs = (deadline - currentTime + 999999) / 1000000;
 
                 if (sleepTimeMs <= 0) {
-                    if (currentTime == Long.MIN_VALUE) {
-                        return -Long.MAX_VALUE;
-                    } else {
-                        return currentTime;
-                    }
+                    return currentTime;

Review comment:
       Long.MIN_VALUE is 1 smaller than -Long.MAX_VALUE
   




-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org