From 89994ba4bce8dcf08fea2d4b659a3836abd41955 Mon Sep 17 00:00:00 2001 From: Federico Bond Date: Sat, 2 Aug 2014 20:48:26 -0300 Subject: [PATCH] Avoid expensive locking on every Language access --- app/src/processing/app/Language.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/processing/app/Language.java b/app/src/processing/app/Language.java index 836b0d211..a82f7b2e9 100644 --- a/app/src/processing/app/Language.java +++ b/app/src/processing/app/Language.java @@ -43,7 +43,7 @@ public class Language { static protected final File prefFile = Base.getSettingsFile(PREF_FILE); /** Single instance of this Language class */ - static private Language instance = null; + static private volatile Language instance; /** The system language */ private String language; @@ -149,9 +149,13 @@ public class Language { /** Singleton constructor */ - static public synchronized Language init() { + static public Language init() { if (instance == null) { - instance = new Language(); + synchronized(Language.class) { + if (instance == null) { + instance = new Language(); + } + } } return instance; }