IDEMPIERE-1044 Load testing. Fixed MCountry.getDefault(ctx) not thread safe.

This commit is contained in:
Heng Sin Low 2013-08-02 22:56:46 +08:00
parent 6cceb11628
commit ff167fd130
1 changed files with 9 additions and 6 deletions

View File

@ -58,8 +58,7 @@ public final class MCountry extends X_C_Country
*/ */
public static MCountry get (Properties ctx, int C_Country_ID) public static MCountry get (Properties ctx, int C_Country_ID)
{ {
if (s_countries == null || s_countries.size() == 0) loadAllCountriesIfNeeded(ctx);
loadAllCountries(ctx);
String key = String.valueOf(C_Country_ID); String key = String.valueOf(C_Country_ID);
MCountry c = (MCountry)s_countries.get(key); MCountry c = (MCountry)s_countries.get(key);
if (c != null) if (c != null)
@ -80,8 +79,7 @@ public final class MCountry extends X_C_Country
*/ */
public static MCountry getDefault (Properties ctx) public static MCountry getDefault (Properties ctx)
{ {
if (s_countries == null || s_countries.size() == 0) loadAllCountriesIfNeeded(ctx);
loadAllCountries(ctx);
return s_default; return s_default;
} // get } // get
@ -92,14 +90,19 @@ public final class MCountry extends X_C_Country
*/ */
public static MCountry[] getCountries(Properties ctx) public static MCountry[] getCountries(Properties ctx)
{ {
if (s_countries == null || s_countries.size() == 0) loadAllCountriesIfNeeded(ctx);
loadAllCountries(ctx);
MCountry[] retValue = new MCountry[s_countries.size()]; MCountry[] retValue = new MCountry[s_countries.size()];
s_countries.values().toArray(retValue); s_countries.values().toArray(retValue);
Arrays.sort(retValue, new MCountry(ctx, 0, null)); Arrays.sort(retValue, new MCountry(ctx, 0, null));
return retValue; return retValue;
} // getCountries } // getCountries
private static synchronized void loadAllCountriesIfNeeded(Properties ctx) {
if (s_countries == null || s_countries.isEmpty()) {
loadAllCountries(ctx);
}
}
/** /**
* Load Countries. * Load Countries.
* Set Default Language to Client Language * Set Default Language to Client Language