From 2320a5919f49c9e5705215b4273db291ea40d1ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Br=C3=A9gier?= Date: Sat, 19 May 2012 14:54:59 +0300 Subject: [PATCH 1/2] Proposal for fix related to 1rst issue of #345 => (getTimeToWait /10)*10 (see http://www.javamex.com/tutorials/threads/sleep_issues.shtml) --- .../io/netty/handler/traffic/AbstractTrafficShapingHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handler/src/main/java/io/netty/handler/traffic/AbstractTrafficShapingHandler.java b/handler/src/main/java/io/netty/handler/traffic/AbstractTrafficShapingHandler.java index 7da4b29a96..b0c6fcfda9 100644 --- a/handler/src/main/java/io/netty/handler/traffic/AbstractTrafficShapingHandler.java +++ b/handler/src/main/java/io/netty/handler/traffic/AbstractTrafficShapingHandler.java @@ -360,7 +360,7 @@ public abstract class AbstractTrafficShapingHandler extends // Time is too short, so just lets continue return 0; } - return bytes * 1000 / limit - interval; + return ((bytes * 1000 / limit - interval)/10)*10; } @Override From bc540d5ee1b1c865bc442d08d3991a800180ca5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Br=C3=A9gier?= Date: Sat, 19 May 2012 14:59:52 +0300 Subject: [PATCH 2/2] Proposal for fix related to 1rst issue of #345 => in configure (newcheckInterval/10)*10 (see http://www.javamex.com/tutorials/threads/sleep_issues.shtml) --- .../main/java/io/netty/handler/traffic/TrafficCounter.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/handler/src/main/java/io/netty/handler/traffic/TrafficCounter.java b/handler/src/main/java/io/netty/handler/traffic/TrafficCounter.java index 6976ac08c5..d8cfdb3fb6 100644 --- a/handler/src/main/java/io/netty/handler/traffic/TrafficCounter.java +++ b/handler/src/main/java/io/netty/handler/traffic/TrafficCounter.java @@ -248,9 +248,10 @@ public class TrafficCounter { * @param newcheckInterval */ public void configure(long newcheckInterval) { - if (checkInterval.get() != newcheckInterval) { - checkInterval.set(newcheckInterval); - if (newcheckInterval <= 0) { + long newInterval = (newcheckInterval/10)*10; + if (checkInterval.get() != newInterval) { + checkInterval.set(newInterval); + if (newInterval <= 0) { stop(); // No more active monitoring lastTime.set(System.currentTimeMillis());