From ff167fd130e0ba17ef88cf5d5dde3e5009c716d1 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Fri, 2 Aug 2013 22:56:46 +0800 Subject: [PATCH] IDEMPIERE-1044 Load testing. Fixed MCountry.getDefault(ctx) not thread safe. --- .../src/org/compiere/model/MCountry.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/MCountry.java b/org.adempiere.base/src/org/compiere/model/MCountry.java index 2531b2a4ec..e8572b8774 100644 --- a/org.adempiere.base/src/org/compiere/model/MCountry.java +++ b/org.adempiere.base/src/org/compiere/model/MCountry.java @@ -58,8 +58,7 @@ public final class MCountry extends X_C_Country */ public static MCountry get (Properties ctx, int C_Country_ID) { - if (s_countries == null || s_countries.size() == 0) - loadAllCountries(ctx); + loadAllCountriesIfNeeded(ctx); String key = String.valueOf(C_Country_ID); MCountry c = (MCountry)s_countries.get(key); if (c != null) @@ -80,8 +79,7 @@ public final class MCountry extends X_C_Country */ public static MCountry getDefault (Properties ctx) { - if (s_countries == null || s_countries.size() == 0) - loadAllCountries(ctx); + loadAllCountriesIfNeeded(ctx); return s_default; } // get @@ -92,14 +90,19 @@ public final class MCountry extends X_C_Country */ public static MCountry[] getCountries(Properties ctx) { - if (s_countries == null || s_countries.size() == 0) - loadAllCountries(ctx); + loadAllCountriesIfNeeded(ctx); MCountry[] retValue = new MCountry[s_countries.size()]; s_countries.values().toArray(retValue); Arrays.sort(retValue, new MCountry(ctx, 0, null)); return retValue; } // getCountries + private static synchronized void loadAllCountriesIfNeeded(Properties ctx) { + if (s_countries == null || s_countries.isEmpty()) { + loadAllCountries(ctx); + } + } + /** * Load Countries. * Set Default Language to Client Language