mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-01-19 08:55:26 +01:00
Switch to countdown latch so we don't need to bother with synchronization blocks. Fixes #4248
This commit is contained in:
parent
d1b7e88b7e
commit
01f111f78d
@ -17,6 +17,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.logging.Level;
|
||||
|
||||
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 final Object awaiter = new Object();
|
||||
private final CountDownLatch awaiter = new CountDownLatch(1);
|
||||
private final mcMMO plugin;
|
||||
private final ImmutableList<String> userNames;
|
||||
private int position = 0;
|
||||
@ -98,12 +99,10 @@ public class UUIDUpdateAsyncTask implements Runnable {
|
||||
position += batch.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);
|
||||
awaiter.notify();
|
||||
}
|
||||
else
|
||||
awaiter.countDown();
|
||||
} else
|
||||
this.runTaskLaterAsynchronously(plugin, Misc.TICK_CONVERSION_FACTOR * DELAY_PERIOD); // Schedule next batch
|
||||
}
|
||||
|
||||
@ -122,7 +121,7 @@ public class UUIDUpdateAsyncTask implements Runnable {
|
||||
|
||||
public void waitUntilFinished() {
|
||||
try {
|
||||
awaiter.wait();
|
||||
awaiter.await();
|
||||
} catch (InterruptedException e) {
|
||||
// I guess we don't care in this event
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user