From: David ‘Bombe’ Roden Date: Thu, 30 Dec 2010 19:56:57 +0000 (+0100) Subject: Try to prevent deadlocks when saving the configuration. X-Git-Tag: beta-freefall-0.6.2-1~174 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=dd546cccbe959487c94e1a95714fb6addd072e53 Try to prevent deadlocks when saving the configuration. --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 807b1f3..1a92901 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -86,6 +86,9 @@ public class Core implements IdentityListener { /** The configuration. */ private Configuration configuration; + /** Whether we’re currently saving the configuration. */ + private boolean storingConfiguration = false; + /** The identity manager. */ private final IdentityManager identityManager; @@ -1416,7 +1419,15 @@ public class Core implements IdentityListener { /** * Saves the current options. */ - public synchronized void saveConfiguration() { + public void saveConfiguration() { + synchronized (configuration) { + if (storingConfiguration) { + logger.log(Level.FINE, "Already storing configuration…"); + return; + } + storingConfiguration = true; + } + /* store the options first. */ try { configuration.getIntValue("Option/InsertionDelay").setValue(options.getIntegerOption("InsertionDelay").getReal()); @@ -1456,6 +1467,10 @@ public class Core implements IdentityListener { } catch (ConfigurationException ce1) { logger.log(Level.SEVERE, "Could not store configuration!", ce1); + } finally { + synchronized (configuration) { + storingConfiguration = false; + } } }