Add workaround to let the sleep work correctly in windows too. See #356
This commit is contained in:
parent
a6685df3e2
commit
3a7ed4b75c
@ -31,6 +31,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
import io.netty.util.internal.ConcurrentIdentityHashMap;
|
||||
import io.netty.util.internal.DetectionUtil;
|
||||
import io.netty.util.internal.ReusableIterator;
|
||||
import io.netty.util.internal.SharedResourceMisuseDetector;
|
||||
|
||||
@ -442,8 +443,17 @@ public class HashedWheelTimer implements Timer {
|
||||
|
||||
for (;;) {
|
||||
final long currentTime = System.currentTimeMillis();
|
||||
final long sleepTime = tickDuration * tick - (currentTime - startTime);
|
||||
|
||||
long sleepTime = tickDuration * tick - (currentTime - startTime);
|
||||
|
||||
// Check if we run on windows, as if thats the case we will need
|
||||
// to round the sleepTime as workaround for a bug that only affect
|
||||
// the JVM if it runs on windows.
|
||||
//
|
||||
// See https://github.com/netty/netty/issues/356
|
||||
if (DetectionUtil.isWindows()) {
|
||||
sleepTime = (sleepTime / 10) * 10;
|
||||
}
|
||||
|
||||
if (sleepTime <= 0) {
|
||||
break;
|
||||
}
|
||||
|
@ -36,7 +36,21 @@ public final class DetectionUtil {
|
||||
|
||||
private static final int JAVA_VERSION = javaVersion0();
|
||||
private static final boolean HAS_UNSAFE = hasUnsafe(AtomicInteger.class.getClassLoader());
|
||||
|
||||
private static final boolean IS_WINDOWS;
|
||||
static {
|
||||
String os = System.getProperty("os.name").toLowerCase();
|
||||
// windows
|
||||
IS_WINDOWS = os.indexOf("win") >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return <code>true</code> if the JVM is running on Windows
|
||||
*
|
||||
*/
|
||||
public static boolean isWindows() {
|
||||
return IS_WINDOWS;
|
||||
}
|
||||
|
||||
public static boolean hasUnsafe() {
|
||||
return HAS_UNSAFE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user