Better solution than synchronization

This commit is contained in:
vemacs 2016-03-02 08:46:29 -07:00
parent 72760096f5
commit e90455463f

View file

@ -22,6 +22,8 @@ public class UUIDMap {
private static final ScheduledExecutorService writeScheduler = Executors.newScheduledThreadPool(1); private static final ScheduledExecutorService writeScheduler = Executors.newScheduledThreadPool(1);
private final Runnable writeTaskRunnable; private final Runnable writeTaskRunnable;
private static boolean loading = false;
public UUIDMap(final net.ess3.api.IEssentials ess) { public UUIDMap(final net.ess3.api.IEssentials ess) {
this.ess = ess; this.ess = ess;
userList = new File(ess.getDataFolder(), "usermap.csv"); userList = new File(ess.getDataFolder(), "usermap.csv");
@ -53,6 +55,7 @@ public class UUIDMap {
names.clear(); names.clear();
history.clear(); history.clear();
loading = true;
try (BufferedReader reader = new BufferedReader(new FileReader(userList))) { try (BufferedReader reader = new BufferedReader(new FileReader(userList))) {
while (true) { while (true) {
@ -79,6 +82,7 @@ public class UUIDMap {
} }
} }
} }
loading = false;
} catch (IOException ex) { } catch (IOException ex) {
Bukkit.getLogger().log(Level.SEVERE, ex.getMessage(), ex); Bukkit.getLogger().log(Level.SEVERE, ex.getMessage(), ex);
} }
@ -115,7 +119,7 @@ public class UUIDMap {
@Override @Override
public void run() { public void run() {
pendingWrite = false; pendingWrite = false;
if (names.isEmpty()) { if (loading || names.isEmpty()) {
return; return;
} }
File configFile = null; File configFile = null;