Add workaround to let the sleep work correctly in windows too. See #356

Conflicts:

	common/src/main/java/io/netty/util/HashedWheelTimer.java
	common/src/main/java/io/netty/util/internal/DetectionUtil.java
This commit is contained in:
Norman Maurer 2012-05-23 15:12:04 +02:00 committed by Trustin Lee
parent f6f246cac0
commit 59b5c3a328
2 changed files with 25 additions and 1 deletions

View File

@ -17,6 +17,7 @@ package io.netty.util;
import io.netty.logging.InternalLogger;
import io.netty.logging.InternalLoggerFactory;
import io.netty.util.internal.DetectionUtil;
import io.netty.util.internal.ReusableIterator;
import io.netty.util.internal.SharedResourceMisuseDetector;
@ -442,7 +443,16 @@ 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;

View File

@ -34,6 +34,20 @@ 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;