diff --git a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java index 81d2838c652d..4d435dbc16d5 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java @@ -32,6 +32,9 @@ import java.io.File; import java.util.List; import java.util.*; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.prefs.BackingStoreException; import java.util.prefs.Preferences; import java.util.stream.Collectors; @@ -327,6 +330,7 @@ public class PreferencesDialog extends javax.swing.JDialog { // auto-update settings on first run public static final String KEY_SETTINGS_VERSION = "settingsVersion"; + private static final ReadWriteLock cacheLock = new ReentrantReadWriteLock(); private static final Map CACHE = new HashMap<>(); public static final String OPEN_CONNECTION_TAB = "Open-Connection-Tab"; @@ -3804,15 +3808,27 @@ public static int getCachedValue(String key, int def) { } public static String getCachedValue(String key, String def) { - if (CACHE.containsKey(key)) { - return CACHE.get(key); - } else { + final Lock r = cacheLock.readLock(); + r.lock(); + try { + if (CACHE.containsKey(key)) { + return CACHE.get(key); + } + } finally { + r.unlock(); + } + + final Lock w = cacheLock.writeLock(); + w.lock(); + try { String value = MageFrame.getPreferences().get(key, def); if (value == null) { - return def; + value = def; } CACHE.put(key, value); return value; + } finally { + w.unlock(); } } diff --git a/Mage.Server/src/main/java/mage/server/ChatSession.java b/Mage.Server/src/main/java/mage/server/ChatSession.java index 98685945b9e9..b58222afbfb2 100644 --- a/Mage.Server/src/main/java/mage/server/ChatSession.java +++ b/Mage.Server/src/main/java/mage/server/ChatSession.java @@ -132,7 +132,7 @@ public void broadcast(String userName, String message, MessageColor color, boole } } if (!clientsToRemove.isEmpty()) { - final Lock w = lock.readLock(); + final Lock w = lock.writeLock(); w.lock(); try { users.keySet().removeAll(clientsToRemove); diff --git a/Mage.Server/src/main/java/mage/server/util/ServerMessagesUtil.java b/Mage.Server/src/main/java/mage/server/util/ServerMessagesUtil.java index 9b04583f10b6..a8bb71ae8639 100644 --- a/Mage.Server/src/main/java/mage/server/util/ServerMessagesUtil.java +++ b/Mage.Server/src/main/java/mage/server/util/ServerMessagesUtil.java @@ -15,6 +15,7 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; @@ -53,13 +54,14 @@ public enum ServerMessagesUtil { } public List getMessages() { - lock.readLock().lock(); + final Lock r = lock.readLock(); + r.lock(); try { List res = new ArrayList<>(this.newsMessages); res.add(this.statsMessage); return res; } finally { - lock.readLock().unlock(); + r.unlock(); } } @@ -68,13 +70,14 @@ private void reloadMessages() { List updatedMessages = new ArrayList<>(readFromFile()); String updatedStats = getServerStatsMessage(); - lock.writeLock().lock(); + final Lock w = lock.writeLock(); + w.lock(); try { this.newsMessages.clear(); this.newsMessages.addAll(updatedMessages); this.statsMessage = updatedStats; } finally { - lock.writeLock().unlock(); + w.unlock(); } } diff --git a/Utils/find_new_cards.pl b/Utils/find_new_cards.pl index d07861d15ae0..1f763e942738 100644 --- a/Utils/find_new_cards.pl +++ b/Utils/find_new_cards.pl @@ -185,13 +185,16 @@ sub get_name_of_card_from_class print ("\n\n\n"); my $set; #print Dumper(\%cards_by_sets); + my $total = 0; foreach $set (sort keys (%cards_by_sets)) { my $cards = $cards_by_sets{$set}; print ("* ", $set, " - added ", scalar @{$cards}, " new cards;", "\n"); foreach my $card (@{$cards}) { + $total++; print (" * ", $card, "\n"); } } + print ("* Total cards: ", $total); } \ No newline at end of file