* Forgot to remove HashedWheelTimer.main()
* More information in HashedWheelTimeout.toString()
This commit is contained in:
parent
473e765f78
commit
ff1a08c412
@ -28,7 +28,6 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.locks.ReadWriteLock;
|
import java.util.concurrent.locks.ReadWriteLock;
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
@ -284,7 +283,7 @@ public class HashedWheelTimer implements Timer {
|
|||||||
int stopIndex;
|
int stopIndex;
|
||||||
|
|
||||||
final long startTime;
|
final long startTime;
|
||||||
long deadline;
|
volatile long deadline;
|
||||||
|
|
||||||
final long initialDelay;
|
final long initialDelay;
|
||||||
long cumulativeDelay;
|
long cumulativeDelay;
|
||||||
@ -354,14 +353,7 @@ public class HashedWheelTimer implements Timer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isExpired() {
|
public boolean isExpired() {
|
||||||
if (cancelled) {
|
return cancelled || System.nanoTime() > deadline;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
long currentTime = System.nanoTime();
|
|
||||||
synchronized (this) {
|
|
||||||
return currentTime > deadline;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void expire() {
|
public void expire() {
|
||||||
@ -378,13 +370,13 @@ public class HashedWheelTimer implements Timer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
long remaining;
|
long currentTime = System.nanoTime();
|
||||||
synchronized (this) {
|
long age = currentTime - startTime;
|
||||||
remaining = deadline - System.nanoTime();
|
long remaining = deadline - currentTime;
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder buf = new StringBuilder();
|
StringBuilder buf = new StringBuilder(192);
|
||||||
buf.append("TimingWheelTimeout(");
|
buf.append(getClass().getSimpleName());
|
||||||
|
buf.append('(');
|
||||||
|
|
||||||
buf.append("initialDelay: ");
|
buf.append("initialDelay: ");
|
||||||
buf.append(initialDelay / 1000000);
|
buf.append(initialDelay / 1000000);
|
||||||
@ -394,6 +386,10 @@ public class HashedWheelTimer implements Timer {
|
|||||||
buf.append(cumulativeDelay / 1000000);
|
buf.append(cumulativeDelay / 1000000);
|
||||||
buf.append(" ms, ");
|
buf.append(" ms, ");
|
||||||
|
|
||||||
|
buf.append("started: ");
|
||||||
|
buf.append(age / 1000000);
|
||||||
|
buf.append(" ms ago, ");
|
||||||
|
|
||||||
buf.append("deadline: ");
|
buf.append("deadline: ");
|
||||||
if (remaining > 0) {
|
if (remaining > 0) {
|
||||||
buf.append(remaining / 1000000);
|
buf.append(remaining / 1000000);
|
||||||
@ -426,18 +422,4 @@ public class HashedWheelTimer implements Timer {
|
|||||||
return buf.append(')').toString();
|
return buf.append(')').toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
Timer timer = new HashedWheelTimer(
|
|
||||||
Executors.newCachedThreadPool(),
|
|
||||||
100, TimeUnit.MILLISECONDS, 4);
|
|
||||||
|
|
||||||
//Timeout timeout = timer.newTimeout(1200, TimeUnit.MILLISECONDS);
|
|
||||||
timer.newTimeout(new TimerTask() {
|
|
||||||
public void run(Timeout timeout) throws Exception {
|
|
||||||
System.out.println(timeout.getExtensionCount() + ": " + timeout);
|
|
||||||
timeout.extend();
|
|
||||||
}
|
|
||||||
}, 1200, TimeUnit.MILLISECONDS);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user