Add ChunkHashTable.awaitCompletion().

This commit is contained in:
sk89q 2014-08-13 07:51:13 -07:00
parent 5ddc4b9251
commit 5b685e71d3

View File

@ -40,6 +40,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
@ -132,6 +133,25 @@ private void rebuild() {
}
}
/**
* Waits until all currently executing background tasks complete.
*
* @param timeout the maximum time to wait
* @param unit the time unit of the timeout argument
* @return {@code true} if this executor terminated and
* {@code false} if the timeout elapsed before termination
* @throws InterruptedException on interruption
*/
public boolean awaitCompletion(long timeout, TimeUnit unit) throws InterruptedException {
ListeningExecutorService previousExecutor;
synchronized (lock) {
previousExecutor = executor;
executor = createExecutor();
}
previousExecutor.shutdown();
return previousExecutor.awaitTermination(timeout, unit);
}
@Override
public void bias(Vector2D chunkPosition) {
checkNotNull(chunkPosition);