[#1246] Fix cpu-spinning regression in HashedWheelTimer

Also remove the usage of System.currentTimeMillis() completely here to make it more consistent and correct
This commit is contained in:
Norman Maurer 2013-04-08 07:01:08 +02:00
parent ded09fc778
commit 2508c76e97

View File

@ -300,7 +300,7 @@ public class HashedWheelTimer implements Timer {
@Override
public Timeout newTimeout(TimerTask task, long delay, TimeUnit unit) {
final long currentTime = System.currentTimeMillis();
final long currentTime = System.nanoTime();
if (task == null) {
throw new NullPointerException("task");
@ -311,9 +311,9 @@ public class HashedWheelTimer implements Timer {
start();
delay = unit.toMillis(delay);
HashedWheelTimeout timeout = new HashedWheelTimeout(task, currentTime + delay);
scheduleTimeout(timeout, delay);
long delayInNanos = unit.toNanos(delay);
HashedWheelTimeout timeout = new HashedWheelTimeout(task, currentTime + delayInNanos);
scheduleTimeout(timeout, delayInNanos);
return timeout;
}
@ -361,7 +361,7 @@ public class HashedWheelTimer implements Timer {
List<HashedWheelTimeout> expiredTimeouts =
new ArrayList<HashedWheelTimeout>();
startTime = System.currentTimeMillis();
startTime = System.nanoTime();
tick = 1;
while (workerState.get() == WORKER_STATE_STARTED) {
@ -444,7 +444,7 @@ public class HashedWheelTimer implements Timer {
long deadline = startTime + tickDuration * tick;
for (;;) {
final long currentTime = System.currentTimeMillis();
final long currentTime = System.nanoTime();
long sleepTimeMs = (deadline - currentTime + 999999) / 1000000;
if (sleepTimeMs <= 0) {
@ -539,7 +539,7 @@ public class HashedWheelTimer implements Timer {
@Override
public String toString() {
long currentTime = System.currentTimeMillis();
final long currentTime = System.nanoTime();
long remaining = deadline - currentTime;
StringBuilder buf = new StringBuilder(192);