summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWesley Wolfe <weswolf@aol.com>2012-08-26 10:25:11 -0500
committerWesley Wolfe <weswolf@aol.com>2012-08-26 10:25:11 -0500
commit3307d489da30d0d2c32fdd5ea834d790b2ee68dc (patch)
tree9cdfced10abb4ed00fdf7717ab1f56dab87728b7
parentcb84d6b9941f40562773950aafdb9dc8682b8537 (diff)
downloadcraftbukkit-3307d489da30d0d2c32fdd5ea834d790b2ee68dc.tar
craftbukkit-3307d489da30d0d2c32fdd5ea834d790b2ee68dc.tar.gz
craftbukkit-3307d489da30d0d2c32fdd5ea834d790b2ee68dc.tar.lz
craftbukkit-3307d489da30d0d2c32fdd5ea834d790b2ee68dc.tar.xz
craftbukkit-3307d489da30d0d2c32fdd5ea834d790b2ee68dc.zip
Fix Future task waiting logic. Fixes BUKKIT-2408
Previously, the timeout would erroneously get converted to milliseconds twice. The second conversion was removed. Spurious wakeups were not handled properly, and would instead throw a TimeoutException even if the waited time was not reached..
-rw-r--r--src/main/java/org/bukkit/craftbukkit/scheduler/CraftFuture.java7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftFuture.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftFuture.java
index de96ec9b..fee49c92 100644
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftFuture.java
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftFuture.java
@@ -48,14 +48,19 @@ class CraftFuture<T> extends CraftTask implements Future<T> {
public synchronized T get(long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
timeout = unit.toMillis(timeout);
long period = this.getPeriod();
+ long timestamp = timeout > 0 ? System.currentTimeMillis() : 0l;
while (true) {
if (period == -1l || period == -3l) {
- this.wait(unit.toMillis(timeout));
+ this.wait(timeout);
period = this.getPeriod();
if (period == -1l || period == -3l) {
if (timeout == 0l) {
continue;
}
+ timeout += timestamp - (timestamp = System.currentTimeMillis());
+ if (timeout > 0) {
+ continue;
+ }
throw new TimeoutException();
}
}