Switch to countdown latch so we don't need to bother with synchronization blocks. Fixes #4248

This commit is contained in:
t00thpick1 2020-08-02 12:56:27 -04:00
parent d1b7e88b7e
commit 01f111f78d

View File

@ -17,6 +17,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.logging.Level; import java.util.logging.Level;
public class UUIDUpdateAsyncTask implements Runnable { public class UUIDUpdateAsyncTask implements Runnable {
@ -29,7 +30,7 @@ public class UUIDUpdateAsyncTask implements Runnable {
private static final int BATCH_SIZE = 100; // 100 at a time private static final int BATCH_SIZE = 100; // 100 at a time
private final Object awaiter = new Object(); private final CountDownLatch awaiter = new CountDownLatch(1);
private final mcMMO plugin; private final mcMMO plugin;
private final ImmutableList<String> userNames; private final ImmutableList<String> userNames;
private int position = 0; private int position = 0;
@ -98,12 +99,10 @@ public class UUIDUpdateAsyncTask implements Runnable {
position += batch.size(); position += batch.size();
plugin.getLogger().info(String.format("Conversion progress: %d/%d users", position, userNames.size())); plugin.getLogger().info(String.format("Conversion progress: %d/%d users", position, userNames.size()));
if (position == userNames.size()) if (position == userNames.size()) {
{
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_UUIDS); mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_UUIDS);
awaiter.notify(); awaiter.countDown();
} } else
else
this.runTaskLaterAsynchronously(plugin, Misc.TICK_CONVERSION_FACTOR * DELAY_PERIOD); // Schedule next batch this.runTaskLaterAsynchronously(plugin, Misc.TICK_CONVERSION_FACTOR * DELAY_PERIOD); // Schedule next batch
} }
@ -122,7 +121,7 @@ public class UUIDUpdateAsyncTask implements Runnable {
public void waitUntilFinished() { public void waitUntilFinished() {
try { try {
awaiter.wait(); awaiter.await();
} catch (InterruptedException e) { } catch (InterruptedException e) {
// I guess we don't care in this event // I guess we don't care in this event
} }