Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-19 21:10:10 +01:00
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..
Dieser Commit ist enthalten in:
Ursprung
cb84d6b994
Commit
3307d489da
@ -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 {
|
public synchronized T get(long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
|
||||||
timeout = unit.toMillis(timeout);
|
timeout = unit.toMillis(timeout);
|
||||||
long period = this.getPeriod();
|
long period = this.getPeriod();
|
||||||
|
long timestamp = timeout > 0 ? System.currentTimeMillis() : 0l;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (period == -1l || period == -3l) {
|
if (period == -1l || period == -3l) {
|
||||||
this.wait(unit.toMillis(timeout));
|
this.wait(timeout);
|
||||||
period = this.getPeriod();
|
period = this.getPeriod();
|
||||||
if (period == -1l || period == -3l) {
|
if (period == -1l || period == -3l) {
|
||||||
if (timeout == 0l) {
|
if (timeout == 0l) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
timeout += timestamp - (timestamp = System.currentTimeMillis());
|
||||||
|
if (timeout > 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
throw new TimeoutException();
|
throw new TimeoutException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren